package com.bbx.taxi.client.Activity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import net.simonvt.menudrawer.MenuDrawer;
import net.simonvt.menudrawer.MenuDrawer.OnDrawerStateChangeListener;
import net.simonvt.menudrawer.Position;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint.Join;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.WindowManager.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.ButterKnife;
import butterknife.InjectView;

import com.baidu.location.BDLocation;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
import com.baidu.mapapi.utils.DistanceUtil;
import com.bbx.androidapi.util.SharedPreUtil;
import com.bbx.androidapi.util.SystemUtil;
import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.gclient.GMsg;
import com.bbx.api.gclient.msg.CouponMsg;
import com.bbx.api.sdk.SDK;
import com.bbx.api.sdk.model.comm.returns.line.Cities;
import com.bbx.api.sdk.model.comm.returns.line.To_Cities;
import com.bbx.api.sdk.model.official.passanger.Officail_OrderSubmitBuild;
import com.bbx.api.sdk.model.official.passanger.Officail_PriceBuild;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Info;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Info.UserInfo;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_OrderInfo;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_OrderSubmit;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Price;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Vehicle.VehicleList;
import com.bbx.api.sdk.model.official.passanger.Return.OrderList.OfficialOrderDetail;
import com.bbx.api.sdk.model.official.passanger.Return.OrderList.OfficialOrderList;
import com.bbx.api.sdk.model.official.passanger.Return.OrderList.OfficialOrders;
import com.bbx.api.sdk.model.official.passanger.Return.OrderList.OrderInfo;
import com.bbx.api.sdk.model.official.passanger.Return.OrderList.OfficialOrderDetail.Uinfo;
import com.bbx.api.sdk.model.passanger.CouponUsableBulid;
import com.bbx.api.sdk.model.passanger.CouponUsableBulid;
import com.bbx.api.sdk.model.passanger.MyOrder;
import com.bbx.api.sdk.model.passanger.PriceBuild;
import com.bbx.api.sdk.model.passanger.Token;
import com.bbx.api.sdk.model.passanger.UserBuild;
import com.bbx.api.sdk.model.passanger.Return.Elements;
import com.bbx.api.sdk.model.passanger.Return.Info;
import com.bbx.api.sdk.model.passanger.Return.OrderDetails;
import com.bbx.api.sdk.model.passanger.Return.OrderId;
import com.bbx.api.sdk.model.passanger.Return.Price;
import com.bbx.api.sdk.model.passanger.Return.User;
import com.bbx.api.sdk.model.passanger.Return.Coupon.CouponList;
import com.bbx.api.sdk.model.passanger.Return.Coupon.Coupons;
import com.bbx.api.sdk.model.passanger.Return.Coupon.Metadata;
import com.bbx.api.sdk.model.passanger.Return.Jmsg.Msgs;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Discount;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.End;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Location;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Start;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Officail_InfoNet;
import com.bbx.api.sdk.net.official.passanger.Officail_OrderSubmitNet;
import com.bbx.api.sdk.net.official.passanger.Officail_PriceNet;
import com.bbx.api.sdk.net.passeger.conn.CouponUsableNet;
import com.bbx.api.sdk.net.passeger.conn.GetUserNet;
import com.bbx.api.sdk.net.passeger.conn.MyOrderNet_Unfini;
import com.bbx.api.sdk.net.passeger.conn.OrderSubmitNet;
import com.bbx.api.sdk.net.passeger.conn.PriceNet;
import com.bbx.taxi.client.Task.BaseAsyncTask;
import com.bbx.api.util.LogUtils;
import com.bbx.api.util.SharedPreEncryptUtil;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.client.MyApplication.OnLocationResultListener;
import com.bbx.taxi.official.R;
import com.bbx.taxi.client.Activity.Address.AddressActivity;
import com.bbx.taxi.client.Activity.Menu.CouponActivity;
import com.bbx.taxi.client.Activity.Menu.UnprocessedActivity;
import com.bbx.taxi.client.Activity.Menu.MessageActivity;
import com.bbx.taxi.client.Activity.Menu.MyOrderActivity;
import com.bbx.taxi.client.Activity.Menu.MyOrderOfficailActivity;
import com.bbx.taxi.client.Activity.Menu.PersonalDataActivity;
import com.bbx.taxi.client.Activity.Menu.RecommenActivity;
import com.bbx.taxi.client.Activity.Menu.SetActivity;
import com.bbx.taxi.client.Activity.Order.OrderCancelReason;
import com.bbx.taxi.client.Activity.Order.OrderDelete;
import com.bbx.taxi.client.Activity.Order.OrderEvaluationActivity;
import com.bbx.taxi.client.Activity.Order.OrderEvaluationActivity2;
import com.bbx.taxi.client.Activity.Order.OrderUnprocessed;
import com.bbx.taxi.client.Activity.Order.StartServiceActivity;
import com.bbx.taxi.client.Activity.login.LoginActivity;
import com.bbx.taxi.client.Adapter.CouponAdapter;
import com.bbx.taxi.client.Adapter.Page.MyPagerFragmentAdapter;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute.OnContentFillingListener;
import com.bbx.taxi.client.Bean.Extra.ExamineMsg;
import com.bbx.taxi.client.Bean.Extra.MainMsg;
import com.bbx.taxi.client.Bean.Extra.OrderMsg;
import com.bbx.taxi.client.Bean.Extra.UseCouponMsg;
import com.bbx.taxi.client.Bean.Message.ObserverListener;
import com.bbx.taxi.client.Bean.Message.Online;
import com.bbx.taxi.client.Bean.Message.Publisher;
import com.bbx.taxi.client.DB.AddressDB;
import com.bbx.taxi.client.DB.JmsgDB;
import com.bbx.taxi.client.DB.LineDB;
import com.bbx.taxi.client.DB.MyOrder.MyOrderDB;
import com.bbx.taxi.client.DB.MyOrder.MyOrderLocationsDB;
import com.bbx.taxi.client.DB.MyOrder.MyOrderingDB;
import com.bbx.taxi.client.DB.Util.DBcolumns;
import com.bbx.taxi.client.Fragment.CarpoolingFragment;
import com.bbx.taxi.client.Fragment.CharteredCarFragment;
import com.bbx.taxi.client.Fragment.CityCarFragment;
import com.bbx.taxi.client.Fragment.CityCarFragment.OnTelInterfaceListener;
import com.bbx.taxi.client.Fragment.ExpressFragment;
import com.bbx.taxi.client.Fragment.OfficialFragment;
import com.bbx.taxi.client.Service.LoginService;
import com.bbx.taxi.client.Service.TimeService;
import com.bbx.taxi.client.Service.TokenService;
import com.bbx.taxi.client.Task.MyLineTask;
import com.bbx.taxi.client.Task.MyLineTask.OnLineFinishListener;
import com.bbx.taxi.client.Task.MyOrderCountTask.OnOrderCountFinishListener;
import com.bbx.taxi.client.Task.MyOrderTask;
import com.bbx.taxi.client.Task.MyOrderTask.OnOrderFinishListener;
import com.bbx.taxi.client.Task.MyOrderCountTask;
import com.bbx.taxi.client.Task.MyTCTask;
import com.bbx.taxi.client.Task.MyVehicleTask;
import com.bbx.taxi.client.Task.MyVehicleTask.OnVehiclelListener;
import com.bbx.taxi.client.Task.OrderDetailTask;
import com.bbx.taxi.client.Task.OrderDetailTask.OnOrderDetailFinishListener;
import com.bbx.taxi.client.Util.AppStarted;
import com.bbx.taxi.client.Util.BackgroundUtils;
import com.bbx.taxi.client.Util.ClickFilter;
import com.bbx.taxi.client.Util.DataCleanManager;
import com.bbx.taxi.client.Util.DateFormat;
import com.bbx.taxi.client.Util.FormatUtil;
import com.bbx.taxi.client.Util.HttpBitmap;
import com.bbx.taxi.client.Util.IsAuditor;
import com.bbx.taxi.client.Util.NetworkDetector;
import com.bbx.taxi.client.Util.OrderListConvert;
import com.bbx.taxi.client.Util.Tel;
import com.bbx.taxi.client.Util.ToCity;
import com.bbx.taxi.client.Util.WakeLockUtil;
import com.bbx.taxi.client.emoji.EmojiParser;
import com.bbx.taxi.client.emoji.MyConvertToMsg;
import com.bbx.taxi.client.widget.Dailog.MessageDialog;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog;
import com.bbx.taxi.client.widget.Dailog.MyBusyDailog;
import com.bbx.taxi.client.widget.Dailog.MyCityNotOpenedDailog;
import com.bbx.taxi.client.widget.Dailog.MyLineNotDialog;
import com.bbx.taxi.client.widget.Dailog.MyLineNotDialog.OnLineClickLeftListener;
import com.bbx.taxi.client.widget.Dailog.MyLineNotDialog.OnLineClickRightListener;
import com.bbx.taxi.client.widget.Dailog.MyPayOrderDailog;
import com.bbx.taxi.client.widget.Dailog.MyTypeDailog;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog.onClickLeftListener;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog.onClickRightListener;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog.onClickSingleListener;
import com.bbx.taxi.client.widget.Dailog.MyPayOrderDailog.onClickPayListener;
import com.bbx.taxi.client.widget.StatusBar.StatusBar;
import com.bbx.taxi.client.widget.SwitchButton.Configuration;
import com.bbx.taxi.client.widget.SwitchButton.SwitchButton;
import com.bbx.taxi.client.widget.pop.CollecteAddressPop.OnAddressPoPViewStateListener;
import com.bbx.taxi.client.widget.pop.CollecteAddressPop;
import com.bbx.taxi.client.widget.pop.DatePicker;
import com.bbx.taxi.client.widget.pop.WheelCustom;
import com.bbx.taxi.client.widget.pop.DatePicker.OnPoPViewStateListener;
import com.bbx.taxi.client.widget.pop.WheelCustom.OnWheelCustomStateListener;
import com.example.Util.DensityUtil;
import com.example.loadview.LoadingDialog;
import com.umeng.analytics.MobclickAgent;

public class MainActivity extends FragmentActivity implements OnClickListener,
		OnPageChangeListener, OnContentFillingListener, OnPoPViewStateListener,
		OnWheelCustomStateListener, OnAddressPoPViewStateListener,
		OnLocationResultListener, OnTelInterfaceListener, ObserverListener,
		OnOrderFinishListener, OnOrderDetailFinishListener,
		OnLineFinishListener ,OnOrderCountFinishListener{
	@InjectView(R.id.layout_citycar)
	RelativeLayout layout_citycar;
	@InjectView(R.id.btn_citycar)
	ImageView btn_citycar;

	@InjectView(R.id.layout_express)
	RelativeLayout layout_express;
	@InjectView(R.id.layout_carpooling)
	RelativeLayout layout_carpooling;
	@InjectView(R.id.layout_charteredcar)
	RelativeLayout layout_charteredcar;
	@InjectView(R.id.btn_express)
	ImageView btn_express;
	@InjectView(R.id.btn_carpooling)
	ImageView btn_carpooling;
	@InjectView(R.id.btn_charteredcar)
	ImageView btn_charteredcar;
	@InjectView(R.id.tv_citycar)
	TextView tv_citycar;
	@InjectView(R.id.tv_express)
	TextView tv_express;
	@InjectView(R.id.tv_carpooling)
	TextView tv_carpooling;
	@InjectView(R.id.tv_charteredcar)
	TextView tv_charteredcar;
	/** 个人信息 */
	@InjectView(R.id.personalDate)
	RelativeLayout personalDate;
	// left
	@InjectView(R.id.tv_real_name)
	TextView tv_real_name;
	@InjectView(R.id.tv_role_name)
	TextView tv_role_name;
	@InjectView(R.id.menu_message)
	TextView menu_message;
	@InjectView(R.id.menu_order)
	TextView menu_order;
	@InjectView(R.id.layout_examine)
	RelativeLayout layout_examine;

	@InjectView(R.id.confirm)
	Button confirm;
	@InjectView(R.id.pop_background)
	View pop_background;
	@InjectView(R.id.bg_transparent)
	View bg_transparent;
	/** 未完成订单提示语 */
	@InjectView(R.id.tv_prompt)
	TextView tv_prompt;
	@InjectView(R.id.layout_main)
	RelativeLayout layout_main;
	// @InjectView(R.id.tv_price)
	// TextView tv_price;
	@InjectView(R.id.tv_coupon_deductible)
	TextView tv_coupon_deductible;
	@InjectView(R.id.re_coupon)
	RelativeLayout re_coupon;
	@InjectView(R.id.layout_city_tel)
	RelativeLayout layout_city_tel;
	@InjectView(R.id.layout_price_comfirm)
	LinearLayout layout_price_comfirm;
	@InjectView(R.id.buttom_bar_group)
	LinearLayout buttom_bar_group;
	@InjectView(R.id.btn_exit)
	Button btn_exit;
	@InjectView(R.id.layout_menu)
	LinearLayout layout_menu;
	@InjectView(R.id.tv_right)
	TextView tv_right;
	@InjectView(R.id.swicthbutton)
	SwitchButton mSwitchButton;
	@InjectView(R.id.tv_ordercount)
	TextView tv_ordercount;
	@InjectView(R.id.iv_new)
	ImageView iv_new;
	// public CityCarFragment mCityCarFragment;
	// public ExpressFragment mExpressFragment;
	// public CarpoolingFragment mCarpoolingFragment;
	// public CharteredCarFragment mCharteredCarFragment;
	public OfficialFragment mOfficialFragment;
	public static int viewId = Value.VIEWID_GW;
	ViewPager viewpager = null;
	ArrayList<Fragment> fragments = null;
	PagerAdapter adapter = null;
	private ImageView iv_left;
	public static Activity context;
	public static MenuDrawer mMenuDrawer;
	private TextView currentTextView;
	private long mkeyTime;
	private MyApplication mApplication;
	private String sn = "push_offline";// 序列号
	/** 可用优惠劵 */
	public static List<Coupons> list_available = new ArrayList<Coupons>();
	/** 是否点开可用优惠劵 */
	private boolean isOpenAvailable = false;
	/** 主界面的信息临时存储 */
	private MainAttribute main;
	private UserTask mUserTask;
	/** 生成可用优惠劵 */
	private CouponUsableTask mCouponUsableTask;
	/** 价格 */
	private PriceTask mPriceTask;
	/** 订单提交 */
	private OrderSubmitTask mOrderSubmitTask;
	private MyOrderingDB db_myordering;// 我的全部的订单数据库
	private MyOrderDB db_myorder;// 我的全部的订单数据库
	private MyOrderLocationsDB db_locations;// 我的订单的Locations数据库
	private AddressDB db_address;// 我的地址
	private LineDB db_line;// 线路数据库
	private Officail_OrderSubmitBuild mOfficail_OrderSubmitBuild;
	private int price;
	private boolean isContinue;
	private CouponAdapter mCouponAdapter;
	/** 加载价格对话框 */
	private LoadingDialog loaddialog;
	/** 不加载价格，，刚登陆的时候不加载 */
	private boolean isNoLoad = false;
	/** 未完成订单 */
	private ArrayList<OfficialOrderList> list_ing = new ArrayList<OfficialOrderList>();
	/** 要提交的订单 */
	OfficialOrderDetail mOfficialOrderDetail;
	String line_id = "";
	int coupon_id = 0;
	private Configuration mConf;
	/** 取消定位 */
	public static boolean isLocation = false;
	public boolean isLocationFail = false;
	public boolean isLoadFinish = false;
	protected int requestCode = 1;
	protected int resultCode = 1;
	private final int DIALOG_SHOW = 0;
	private final int DIALOG_DISMISS = 1;
	private final int CONFIRM_CLICK = 2;
	private final int CONFIRM_NOCLICK = 3;
	private final int PROMPT_VISIBLE = 4;
	private final int PROMPT_GONE = 5;
	public String SDCARD_PATH = Environment.getExternalStorageDirectory()
			.toString();
	public String LOG_PATH = SDCARD_PATH + "/bbxpc/log/client";
	/** 判断是否是电话界面 */
	public static boolean isTelInteface = false;
	/** 判断是否在请求价格 */
	private boolean isPrice = false;
	/** 存储车的类型对应车型 */
	float x1 = 0;
	float x2 = 0;
	float y1 = 0;
	float y2 = 0;
	public static Map<Integer, ArrayList<VehicleList>> map_vclass = new HashMap<Integer, ArrayList<VehicleList>>();
	// ////////////////////////////////ViewPage监听////////////////////////////////////////////////
	public interface MyOnPageScrolledListener {
		public void onPageScrolled(int viewid);
	}

	public ArrayList<MyOnPageScrolledListener> mMyOnPageScrolledListener_list = new ArrayList<MyOnPageScrolledListener>();

	public void setMyOnPageScrolledListener(MyOnPageScrolledListener l) {
		if (!mMyOnPageScrolledListener_list.contains(l))
			mMyOnPageScrolledListener_list.add(l);
	}

	private void initFragment() {
		// mCityCarFragment = new CityCarFragment();
		// mExpressFragment = new ExpressFragment();
		// mCarpoolingFragment = new CarpoolingFragment();
		// mCharteredCarFragment = new CharteredCarFragment();
		mOfficialFragment = new OfficialFragment();
	}

	// //////////////////////主界面返回监听//////////////////////////////////////////////
	public interface OnActivityResultListener {
		/**
		 * 主界面返回监听
		 */
		public void OnActivityResulFinish();
	}

	public OnActivityResultListener mOnActivityResultListener;

	public void setOnActivityResultListener(OnActivityResultListener l) {
		this.mOnActivityResultListener = l;
	}

	// ///////////////////////////价格监听//////////////////////////////////////
	/**
	 * 价格监听，用于framents界面
	 * 
	 */
	public interface OnPriceListener {
		/**
		 * 价格监听，用于framents界面 isTaxi 是否是出租车
		 */
		public void onPrice(Officail_Price mOfficail_Price, boolean isVisible,
				boolean isTaxi);
	};

	public ArrayList<OnPriceListener> mOnPriceListener_list = new ArrayList<MainActivity.OnPriceListener>();

	public void setOnPriceListener(OnPriceListener l) {
		if (!mOnPriceListener_list.contains(l))
			mOnPriceListener_list.add(l);
	}

	public void removeOnPriceListener(OnPriceListener l) {
		mOnPriceListener_list.remove(l);
	}

	// ////////////////////touch监听//////////////////////////////////////////
	/**
	 * 以下的几个方法用来，让fragment能够监听touch事件
	 */
	private ArrayList<MyOnTouchListener> onTouchListeners = new ArrayList<MyOnTouchListener>();

	public void registerMyOnTouchListener(MyOnTouchListener myOnTouchListener) {
		if (!onTouchListeners.contains(myOnTouchListener)){
	    	onTouchListeners.add(myOnTouchListener);
		}
	}

	public void unregisterMyOnTouchListener(MyOnTouchListener myOnTouchListener) {
		onTouchListeners.remove(myOnTouchListener);
	}

	public interface MyOnTouchListener {
		public boolean onTouch(MotionEvent ev);
	}
	//////////////////////////SwitchButton监听////////////////////////////////////
	private ArrayList<OnSwitchButtonListener> mOnSwitchButtonListenerlist = new ArrayList<OnSwitchButtonListener>();

	public void setOnSwitchButtonListener(OnSwitchButtonListener l) {
		if (!mOnSwitchButtonListenerlist.contains(l)){
			mOnSwitchButtonListenerlist.add(l);
		}
	}

	public void removeOnSwitchButtonListener(OnSwitchButtonListener l) {
		mOnSwitchButtonListenerlist.remove(l);
	}

	public interface OnSwitchButtonListener {
		public void onSwitchButton(boolean opened);
	}
////////////////////////////////////////////////////////////

	protected void onCreate(Bundle savedInstanceState) {
		StatusBar.setTranslucentStatus(this, true);
		WakeLockUtil.setWifiNeverSleep(this);
		if (getIntent().getExtras() != null) {
			if (getIntent().getExtras().getInt(MainMsg.extra_quit) == MainMsg.INTENT_QUIT) {
				// 退出登录
				// finish();
			}
		}
		mApplication = MyApplication.getInstance();
		initFragment();
		setNotifiExtras();
		super.onCreate(savedInstanceState);
		context = this;
		loaddialog = new LoadingDialog(MainActivity.this, true);
		mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.Type.BEHIND,
				Position.START, MenuDrawer.MENU_DRAG_CONTENT);
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		mMenuDrawer.setMenuSize((int) (dm.widthPixels * 0.85));
		// mMenuDrawer.setMenuSize((int) (dm.widthPixels ));
		mMenuDrawer.setMenuView(R.layout.leftmenu_officail);// 设置菜单视图
		mMenuDrawer.setContentView(R.layout.main);
		// 去掉阴影
		mMenuDrawer.setDropShadowEnabled(false);
		mMenuDrawer
				.setOnDrawerStateChangeListener(new OnDrawerStateChangeListener() {
					@Override
					public void onDrawerStateChange(int oldState, int newState) {
					}

					@Override
					public void onDrawerSlide(float openRatio, int offsetPixels) {
						if (openRatio != 0) {
							bg_transparent.setVisibility(View.VISIBLE);
							double totle = 255 * 0.25;
							int bgAlpha = (int) (totle * openRatio);
							layout_main.getBackground().setAlpha(255 - bgAlpha);
							bg_transparent.getBackground().setAlpha(
									(int) (bgAlpha + (65 * openRatio)));
							// 完全打开
							if (openRatio == 1) {
								if (mApplication.getUid() != null
										&& !mApplication.equals("")
										&& mApplication.getToken() != null
										&& !mApplication.getToken().equals("")) {
								} else {
									Intent intent = new Intent(context,
											LoginActivity.class);
									intent.putExtra(MainMsg.extra_login,
											MainMsg.INTENT_LOGIN);
									intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
									startActivity(intent);
									mHandler.postDelayed(new Runnable() {
										@Override
										public void run() {
											mMenuDrawer.closeMenu();
										}
									}, 500);
								}
							}
						} else {
							bg_transparent.setVisibility(View.GONE);
						}

					}
				});

		ButterKnife.inject(this);
		init();

	}

	/**
	 * 通知栏点击进来
	 */
	public void setNotifiExtras() {
		// 记得要先清理掉所有的推送Activity的观察者，因为如果之前HOME键出去，然后点击通知栏进来，，之前的观察者还在
		// 所有就好推送到之前的Activity了
		Publisher.getInstance().clear();
		// 程序关闭的时候点击状态栏跳转
		if (getIntent().getExtras() != null) {// 主要位置
			db_myorder = new MyOrderDB(this);
			if (getIntent().getExtras().getInt(MainMsg.extra_notification) == MainMsg.NOTIFICATION_MAIN) {
				String order_id = getIntent().getExtras().getString(
						MainMsg.extra_notification_orderid);
				boolean isUnprocessed = getIntent().getExtras().getBoolean(
						MainMsg.extra_notification_isunprocessed);
				if (isUnprocessed) {
					startActivity(new Intent(MainActivity.this,
							UnprocessedActivity.class));
				} else {
					OfficialOrderList mOfficialOrderList = db_myorder.onReadDB(
							this, order_id);
					if (mOfficialOrderList != null) {
						try {
							mApplication.onStartLocation();
						} catch (Exception e) {
						}
						String audit_status = mOfficialOrderList
								.getAudit_status();
						int order_status = Integer.parseInt(mOfficialOrderList
								.getOrder_status());
						if (order_status == Value.ORDER_STATUS_UNTREATED
								&& audit_status != null
								&& audit_status.equals(Value.STATUS_AUDIT_NO)) {
							OrderUnprocessed.setOrder(mOfficialOrderList,
									order_id);
							context.startActivity(new Intent(context,
									OrderUnprocessed.class)
									.putExtra(ExamineMsg.EXAMINE_TYPE,
											ExamineMsg.TYPE_OF).putExtra(
											ExamineMsg.EXAMINE_STATUS,
											ExamineMsg.STATUS_NO));
						} else if (order_status == Value.ORDER_STATUS_UNTREATED
								&& audit_status != null
								&& audit_status
										.equals(Value.STATUS_AUDIT_NOPASS)) {
							OrderUnprocessed.setOrder(mOfficialOrderList,
									order_id);
							context.startActivity(new Intent(context,
									OrderUnprocessed.class)
									.putExtra(ExamineMsg.EXAMINE_TYPE,
											ExamineMsg.TYPE_OF).putExtra(
											ExamineMsg.EXAMINE_STATUS,
											ExamineMsg.STATUS_AGAIN));
						}
						// 审核通过
						else {
							if (order_status == 0) {
								// 找不到该订单这获取网络数据
								OrderDetailTask.getInstance(context,
										mApplication, order_id)
										.setOnOrderDetailFinishListener(this);
							} else {
								if (order_status < Value.ORDER_STATUS_OFFCAR
										|| order_status == Value.ORDER_STATUS_GAIPAI
										|| order_status == Value.ORDER_STATUS_KF_GAIPAI) {
									Intent intent = new Intent(this,
											StartServiceActivity.class);
									intent.putExtra(OrderMsg.extra_type, 1);
									intent.putExtra(OrderMsg.extra_order_id,
											mOfficialOrderList.getOrder_id());
									startActivityForResult(intent, requestCode);
								} else if (order_status == Value.ORDER_STATUS_FINISH
										|| order_status == Value.ORDER_STATUS_OFFCAR) {
									Intent intent = new Intent(context,
											OrderEvaluationActivity2.class);
									intent.putExtra(OrderMsg.order_id_finish,
											mOfficialOrderList.getOrder_id());
									intent.putExtra(OrderMsg.finish_type,
											OrderMsg.finish_ing);
									startActivityForResult(intent, requestCode);
								} else if (order_status == Value.ORDER_STATUS_CANCEL
										|| order_status == Value.ORDER_STATUS_KF_CANCEL) {
									Intent intent = new Intent(context,
											OrderCancelReason.class);
									intent.putExtra(OrderMsg.extra_order_id,
											mOfficialOrderList.getOrder_id());
									startActivity(intent);
								} else if (order_status == Value.ORDER_STATUS_DELETE) {
									Intent intent = new Intent(context,
											OrderDelete.class);
									startActivity(intent);
								} else {
									Intent intent = new Intent(context,
											OrderEvaluationActivity2.class);
									intent.putExtra(OrderMsg.order_id_finish,
											mOfficialOrderList.getOrder_id());
									intent.putExtra(OrderMsg.finish_type,
											OrderMsg.finish_all);
									startActivityForResult(intent, requestCode);
								}

							}
						}
					}
				}
			}
		}
	}

	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		// 这里一定要重新赋值，，因为再次下单有各种类型
		viewId = Value.VIEWID_GW;
		boolean islogin = false;
		if (intent.getExtras() != null) {
			islogin = intent.getExtras().getBoolean(MainMsg.extra_success);
		}
		// 如果是登陆跳转过来的，则不赋值mApplication.isFirstActivity =
		// false;因为算第一次启动了，所以不能false
		if (!islogin) {
			mApplication.isFirstActivity = false;
		}
		setNotifiExtras();
		initFragment();
		mMenuDrawer.closeMenu(false);
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				map_vclass.clear();
				init();
			}
		}, 0);

	}

	@Override
	protected void onResume() {
		startService(new Intent(context, TimeService.class));
		MobclickAgent.onResume(this);
		Publisher.getInstance().addOb(this);
		// if (!mApplication.isFirstActivity) {
		// getMyOrder_ING(false, null);
		// }
		MyOrderCountTask.getInstance(context, 1).setOnOrderCountFinishListener(this);
		getMyOrder_ING(false, null);
		super.onResume();
		if (!Value.isActive) {
			// app 从后台唤醒，进入前台
			Value.isActive = true;
			if (Value.isUnSDK) {
				if (mApplication.isUidAndTokenNull()) {
					ToastUtil.showToast(context, R.string.account_exception);
					Intent intent = new Intent(this, LoginActivity.class);
					intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(intent);
				}

			}
			if (mApplication != null) {
				MyOrderTask.getInstance(context, MyOrderActivity.num_ing,
						Value.TYPE_ING,Value.OWNALL, MyOrderTask.TYPE_REFRESH)
						.setOnOrderFinishListener(this);
			}
		}
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

	@Override
	protected void onStop() {
		super.onStop();
		MyOrderTask.removeOnOrderFinishListener(this);
		if (!AppStarted.isRunningForeground(this)) {
			// 记录当前已经进入后台app 进入后台
			Value.isActive = false;
		}
	}

	private void init() {
		main = MainAttribute.getInstance();
		main.setOnContentFillingListener(this);
		mApplication.authority = SharedPreUtil.getStringValue(this,
				SharedPreEncryptUtil.authority, "");
		if (IsAuditor.isAuditor(mApplication.authority)) {
			layout_examine.setVisibility(View.VISIBLE);
			tv_right.setVisibility(View.VISIBLE);
			tv_right.setText(getString(R.string.menu_examine));
		} else {
			layout_examine.setVisibility(View.GONE);
			tv_right.setVisibility(View.GONE);
		}
		mApplication.setOnLocationResultListener(this);
		MyLineTask.getInstance(context).setOnLineFinishListener(this);
		MyTCTask.getInstance(context);
		MyOrderTask.getInstance(context, MyOrderActivity.num_ing,
				Value.TYPE_ING,Value.OWNALL, MyOrderTask.TYPE_REFRESH);
		LoginService.SDKlogin = false;
		// // 判断Token
		startService(new Intent(context, TokenService.class));
		db_myorder = new MyOrderDB(this);
		db_myordering = new MyOrderingDB(this);
		db_locations = new MyOrderLocationsDB(this);
		db_address = new AddressDB(this);
		db_line = new LineDB(this);
		viewpager = (ViewPager) findViewById(R.id.viewpager);
		fragments = new ArrayList<Fragment>();
		fragments.add(mOfficialFragment);// 公务车
		buttom_bar_group.setVisibility(View.GONE);
		adapter = new MyPagerFragmentAdapter(getSupportFragmentManager(),
				fragments);
		viewpager.setAdapter(adapter);
		// 设置缓存个数
		viewpager.setOffscreenPageLimit(fragments.size());
		viewpager.setOnPageChangeListener(this);
		// 展开个人中心按钮
		iv_left = (ImageView) findViewById(R.id.title_bar).findViewById(
				R.id.iv_left);
		iv_left.setOnClickListener(this);
		//
		layout_citycar.setOnClickListener(this);
		layout_express.setOnClickListener(this);
		layout_carpooling.setOnClickListener(this);
		layout_charteredcar.setOnClickListener(this);
		personalDate.setOnClickListener(this);

		menu_message.setOnClickListener(this);
		menu_order.setOnClickListener(this);
		layout_examine.setOnClickListener(this);
		confirm.setOnClickListener(this);
		pop_background.setOnClickListener(this);
		tv_prompt.setOnClickListener(this);
		re_coupon.setOnClickListener(this);
		layout_city_tel.setOnClickListener(this);
		btn_exit.setOnClickListener(this);
		tv_right.setOnClickListener(this);
		// tv_kftel.setText(Value.TEL_KF);
		// if (mOfficialFragment != null) {
		// mCityCarFragment.setOnTelInterfaceListener(this);
		// } else {
		// initFragment();
		// if (mCityCarFragment != null) {
		// mCityCarFragment.setOnTelInterfaceListener(this);
		// }
		// }
		if (mOfficialFragment == null) {
			initFragment();
		}
		DatePicker.setOnPoPViewStateListener(this);
		WheelCustom.setOnWheelCustomStateListener(this);
		CollecteAddressPop.setOnAddressPoPViewStateListener(this);
		// 隐藏价格
		setConfirm(false);
		Intent intent = getIntent();
		if (intent.getExtras() != null) {
			viewId = intent.getExtras().getInt(MainMsg.extra_viewpageId,
					Value.VIEWID_GW);
			// 如果是再次下单则
			if (intent.getExtras().getBoolean(MainMsg.extra_agin_xiadan, false)) {
			}
			isNoLoad = intent.getExtras().getBoolean(MainMsg.extra_success);
			if (isNoLoad) {
				if (mApplication.getUid() != null && !mApplication.equals("")
						&& mApplication.getToken() != null
						&& !mApplication.getToken().equals("")) {
					// 启动登陆Service
					startService(new Intent(this, LoginService.class));
					// bindService(new Intent(this, CallbackService.class),
					// mApplication.conn, BIND_AUTO_CREATE);
					// 获取用户信息
					getInfo(SharedPreUtil.getBooleanValue(this,
							SharedPreEncryptUtil.isLoadOrder_ing, true));
				}
			}
		} else {
			viewId = Value.VIEWID_GW;
			if (mApplication.getUid() != null && !mApplication.equals("")
					&& mApplication.getToken() != null
					&& !mApplication.getToken().equals("")) {
				// 启动登陆Service
				startService(new Intent(this, LoginService.class));
				// bindService(new Intent(this, CallbackService.class),
				// mApplication.conn, BIND_AUTO_CREATE);
				// 获取用户信息
				getInfo(SharedPreUtil.getBooleanValue(this,
						SharedPreEncryptUtil.isLoadOrder_ing, true));
			}
		}
		viewpager.setCurrentItem(viewId);
		// switch (viewId) {
		// case Value.VIEWID_SN:
		// mCityCarFragment.onLocationResult();
		// setButton(btn_citycar, tv_citycar);
		// break;
		// case Value.VIEWID_KJ:
		// setButton(btn_express, tv_express);
		// break;
		// case Value.VIEWID_PC:
		// setButton(btn_carpooling, tv_carpooling);
		// break;
		// case Value.VIEWID_BC:
		// setButton(btn_charteredcar, tv_charteredcar);
		// break;
		// }
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				if (Value.need_fetch_pic != null
						&& !Value.need_fetch_pic.equals("")) {
					// 图片资源
					String url = Value.need_fetch_pic;
					HttpBitmap.getHttpBitmap(context, url);
				}
			}
		}, 500);
		if (mApplication.getUid() != null && !mApplication.equals("")
				&& mApplication.getToken() != null
				&& !mApplication.getToken().equals("")) {
			mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
		} else {
			mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_NONE);
		}
		layout_main.setVisibility(View.VISIBLE);

		initView();
	}

	private void initView() {
		tv_real_name.setText(mApplication.getRealName().equals("") ? context
				.getString(R.string.passenger) : mApplication.getRealName());
		tv_role_name.setText(mApplication.getRoleName().equals("") ? ""
				: mApplication.getRoleName());
		if (mApplication.getUserphone() != null
				&& !mApplication.getUserphone().equals("")) {
			// tv_phone.setText(FormatUtil
			// .onFormatTelephone(mApplication.user_phone));
		} else {
			// tv_phone.setText("");
		}
		if (main.getTel() != null && !main.getTel().equals("")
				&& main.getName() != null) {
			// if (mExpressFragment.tv_start_person != null) {
			// mExpressFragment.tv_start_person.setText((main.getName()
			// .equals("") ? (context.getString(R.string.i)) : main
			// .getName())
			// + "-" + FormatUtil.onFormatTelephone(main.getTel()));
			// }
			// if (mCarpoolingFragment.tv_telephone != null) {
			// mCarpoolingFragment.tv_telephone.setText((main.getName()
			// .equals("") ? context.getString(R.string.i) : main
			// .getName())
			// + "-" + FormatUtil.onFormatTelephone(main.getTel()));
			// }
			// if (mCharteredCarFragment.tv_telephone != null) {
			// mCharteredCarFragment.tv_telephone.setText((main.getName()
			// .equals("") ? context.getString(R.string.i) : main
			// .getName())
			// + "-" + FormatUtil.onFormatTelephone(main.getTel()));
			// }
			if (mOfficialFragment.tv_telephone != null) {
				mOfficialFragment.tv_telephone.setText((main.getName().equals(
						"") ? context.getString(R.string.i) : main.getName())
						+ "-" + FormatUtil.onFormatTelephone(main.getTel()));
			} else {
				if (!mMyOnPageScrolledListener_list.isEmpty()) {
					for (int i = 0; i < mMyOnPageScrolledListener_list.size(); i++) {
						mMyOnPageScrolledListener_list.get(i).onPageScrolled(
								Value.VIEWID_GW);
					}
				}
			}
		}
		initSwitchButton();
	}
	/**
	 * 初始化开关按钮
	 */
	public void initSwitchButton() {
		final String PT = "自费";
		final String GW = "公费";
		// 获取资源配置，只能修改
		mConf = mSwitchButton.getConfiguration();
		mConf.setOnColor(Color.parseColor("#135a92"));
		mConf.setOnTextColor(getResources().getColor(R.color.white_40));
		mConf.setOnText(GW);
		mConf.setOffColor(Color.parseColor("#135a92"));
		mConf.setOffTextColor(getResources().getColor(R.color.white_40));
		mConf.setOffText(PT);
		mConf.setThumbColor(Color.parseColor("#2878bf"));
		mConf.setThumbPressedColor(Color.parseColor("#2878bf"));
		mConf.setThumbTextColor(getResources().getColor(R.color.white));
		mConf.setTextSize(DensityUtil.dip2px(context, 14));
		mConf.setThumbWidthAndHeightInPixel(DensityUtil.dip2px(context, 70),
				DensityUtil.dip2px(context, 30));
		mConf.setMeasureFactor(1.8f);// 设置背景跟开关相差倍数
		mConf.setThumbMarginInPixel(1);
		mConf.setVelocity(10);
		mConf.setTextPadding(DensityUtil.dip2px(context, 15));
		// //提交配置
		mSwitchButton.setConfiguration(mConf);
		if (main.getOwn_expense() == Value.OWN) {
			mSwitchButton.setChecked(true);
			if (!mOnSwitchButtonListenerlist.isEmpty()) {
				for (int i = 0; i < mOnSwitchButtonListenerlist.size(); i++) {
					mOnSwitchButtonListenerlist.get(i).onSwitchButton(true);
			  }
			}
			mConf.setThumbText(PT);
			main.setOwner_type(0);
		} else {
			mSwitchButton.setChecked(false);
			if (!mOnSwitchButtonListenerlist.isEmpty()) {
				for (int i = 0; i < mOnSwitchButtonListenerlist.size(); i++) {
					mOnSwitchButtonListenerlist.get(i).onSwitchButton(false);
			  }
			}
			mConf.setThumbText(GW);
			main.setOwner_type(1);
		}

		mSwitchButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
		
				if (isChecked) {
					main.setOwn_expense(Value.OWN);
					mConf.setThumbText(PT);
					main.setOwner_type(0);
					mSwitchButton.setConfiguration(mConf);
				} else {
					mConf.setThumbText(GW);
					main.setOwner_type(1);
					main.setOwn_expense(Value.NOOWN);
					mSwitchButton.setConfiguration(mConf);
				}
				if (!mOnSwitchButtonListenerlist.isEmpty()) {
					for (int i = 0; i < mOnSwitchButtonListenerlist.size(); i++) {
						mOnSwitchButtonListenerlist.get(i).onSwitchButton(isChecked);
				  }
				}	
			}
		});
  
	
	}
	/**
	 * 获取用户消息
	 */
	public void getInfo(boolean isNet) {
		if (isNet) {
			UserBuild mUserBuild = new UserBuild(this);
			mUserBuild.uid = mApplication.getUid();
			mUserTask = new UserTask(context, mUserBuild);
			mUserTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
		}
	}

	/**
	 * 获取未完成订单,type为0的时候，是先获取未完成订单，然后在执行提交动作
	 */
	public void getMyOrder_ING(boolean isNet, ArrayList<OfficialOrderList> list) {
		if (!mApplication.isUidAndTokenNull()) {
			if (NetworkDetector.detect(this)) {
				if (isNet) {
					if (list_ing != null && list != null && list.size() > 0) {
						list_ing.clear();
						list_ing.addAll(list);
						if (list_ing.size() > 0) {
							mHandler.sendEmptyMessageAtTime(PROMPT_VISIBLE,
									1000);
							tv_prompt.setText(String.format(getResources()
									.getString(R.string.prompt_ordering),
									list_ing.size()));
							showNDailog();
						}
					} else {
						mHandler.sendEmptyMessageAtTime(PROMPT_GONE, 1000);
					}
				} else {
					new AsyncTask<Void, Void, Void>() {

						@Override
						protected Void doInBackground(Void... arg0) {
							list_ing = db_myordering.onReadDB_ing(context,
									MyOrderActivity.num_ing, false);
							return null;
						}

						@Override
						protected void onPostExecute(Void result) {
							if (list_ing != null) {
								if (list_ing.size() > 0) {
									mHandler.sendEmptyMessageAtTime(
											PROMPT_VISIBLE, 1000);
									tv_prompt.setText(String.format(
											getResources().getString(
													R.string.prompt_ordering),
											list_ing.size()));
									showNDailog();
								} else {
									mHandler.sendEmptyMessageAtTime(
											PROMPT_GONE, 1000);
								}
							} else {
								mHandler.sendEmptyMessageAtTime(PROMPT_GONE,
										1000);
							}
							super.onPostExecute(result);
						}

					}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

				}
			}
		} else {
			mHandler.sendEmptyMessageAtTime(PROMPT_GONE, 1000);
		}

	}

	/**
	 * 弹出N笔对话框
	 */
	public void showNDailog() {
		// if (!mApplication.isFirstClient)
		// return;
		// mApplication.isFirstClient = false;
		// new Handler().postDelayed(new Runnable() {
		// @Override
		// public void run() {
		// final MyAlertDailog dialog = new MyAlertDailog(
		// MainActivity.this);
		// dialog.setTitle(null);
		// dialog.setContent(String.format(
		// getResources().getString(R.string.prompt_ordering),
		// list_ing.size()));
		// dialog.setLeftButtonText(getResources().getString(
		// R.string.mydailog_know));
		// dialog.setRightButtonText(getResources().getString(
		// R.string.mydailog_go_see));
		// if (dialog != null && !dialog.isShowing()) {
		// dialog.show();
		// }
		// dialog.setOnClickLeftListener(new onClickLeftListener() {
		// @Override
		// public void onClickLeft() {
		// dialog.dismiss();
		// }
		// });
		// dialog.setOnClickRightListener(new onClickRightListener() {
		//
		// @Override
		// public void onClickRight() {
		// dialog.dismiss();
		// // 跳转到订单详情界面
		// if (list_ing.size() == 1) {
		// Intent intent = new Intent(context,
		// StartServiceActivity.class);
		// intent.putExtra(OrderMsg.extra_type, 0);
		// startActivityForResult(intent, requestCode);
		// }
		// if (list_ing.size() > 1) {
		// startActivity(new Intent(MainActivity.this,
		// MyOrderActivity.class));
		// }
		// }
		// });
		// }
		// }, 200);
	}

	/**
	 * 获取价格
	 */
	public void getPrice() {
		// 如果价格正在加载，则不重复加载
		if (isPrice) {
			return;
		}
		if (Integer.parseInt(main.getVtype()) == Value.taxi_vtype) {
			onShowSubmitPopView(null, true);
			return;
		}
		if (!NetworkDetector.detect(this)) {
			ToastUtil.showToast(context,
					getResources().getString(R.string.no_network));
			return;
		}
		Officail_PriceBuild mOfficail_PriceBuild = new Officail_PriceBuild(this);
		mOfficail_PriceBuild.type = Integer.parseInt(main.getVtype());
		mOfficail_PriceBuild.car_level = Integer.parseInt(main.getLevelCar());
		mOfficail_PriceBuild.owner_type = main.getOwner_type();
		mOfficail_PriceBuild.car_seats = Integer.parseInt(main.getSeat_num());
		mOfficail_PriceBuild.start_time = Long.parseLong(DateFormat
				.getDateToTimeStamp(main.getTime()));
		mOfficail_PriceBuild.tc_id = main.getTc_id();
		LatLng p1LL = new LatLng(main.getStartLatitude(),
				main.getStartLongitude());
		LatLng p2LL = new LatLng(main.getEndLatitude(), main.getEndLongitude());
		int miles = (int) DistanceUtil.getDistance(p1LL, p2LL);
		mOfficail_PriceBuild.miles = main.getOwn_expense()==Value.NOOWN?(main.getWf() ? miles * 2 : miles):miles;
		mOfficail_PriceBuild.round_trip =main.getOwn_expense()==Value.NOOWN?( main.getWf() ?
				Integer.parseInt(Value.ROUND_TRIP): Integer.parseInt(Value.ROUND_TRIP_NO)): Integer.parseInt(Value.ROUND_TRIP_NO);
		mOfficail_PriceBuild.client_type=0;
		mOfficail_PriceBuild.client_version=SystemUtil.getAppVersionName(context);
		mOfficail_PriceBuild.origin=0;
		// tv_price.setVisibility(View.GONE);
		// tv_price.setVisibility(View.VISIBLE);
		mHandler.sendEmptyMessage(DIALOG_SHOW);
		mPriceTask = new PriceTask(this, mOfficail_PriceBuild);
		mPriceTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

	} 

	/**
	 * 生成可用优惠劵
	 * 
	 * @param price
	 */
	public void getCouponUsable(int price) {

		CouponUsableBulid mCouponUsable = new CouponUsableBulid(this);
		mCouponUsable.uid = mApplication.getUid();
		mCouponUsable.access_token = mApplication.getToken();
		mCouponUsable.ordertime = DateFormat.onDate_Long(main.getTime()) / 1000;
		mCouponUsable.ordersum = 0;
		switch (viewId) {
		case Value.VIEWID_SN:
			mCouponUsable.ordertype = Value.ORDER_TYPE_SN;
			break;
		case Value.VIEWID_KJ:
			mCouponUsable.ordertype = Value.ORDER_TYPE_KJ;
			break;
		case Value.VIEWID_PC:
			mCouponUsable.ordertype = Value.ORDER_TYPE_PC;
			break;
		case Value.VIEWID_BC:
			mCouponUsable.ordertype = Value.ORDER_TYPE_BC;
		default:
			break;
		}

		mCouponUsable.lineid = line_id;
		mCouponUsableTask = new CouponUsableTask(context, mCouponUsable, price);
		mCouponUsableTask.execute();
	}

	private class UserTask extends BaseAsyncTask {
		private UserBuild mUserBuild;
		private UserBuild user;

		public UserTask(Activity context, UserBuild mUserBuild) {
			super(context, false, 0);
			this.mUserBuild = mUserBuild;
		}

		@Override
		public void onSuccess(Object object) {
			// TODO Auto-generated method stub
			if (object != null) {
				Officail_Info user = (Officail_Info) object;
				UserInfo info = user.getInfo();
				mApplication.user_name = info.user_name;
				mApplication.user_phone = info.phone;
				mApplication.real_phone = info.phone;
				mApplication.user_sex = info.sex;
				mApplication.real_name = info.getRealName();
				mApplication.role_name = info.getRoleName();
				if (IsAuditor.isAuditor(info.authority)) {
					layout_examine.setVisibility(View.VISIBLE);
					tv_right.setVisibility(View.VISIBLE);
					tv_right.setText(getString(R.string.menu_examine));
				} else {
					layout_examine.setVisibility(View.GONE);
					tv_right.setVisibility(View.GONE);
				}
				SharedPreUtil.putStringValue(MainActivity.this,
						SharedPreEncryptUtil.real_name,
						mApplication.getRealName());
				SharedPreUtil.putStringValue(MainActivity.this,
						SharedPreEncryptUtil.role_name,
						mApplication.getRoleName());
				SharedPreUtil.putStringValue(MainActivity.this,
						SharedPreEncryptUtil.user_name,
						mApplication.getUserName());
				SharedPreUtil.putStringValue(MainActivity.this,
						SharedPreEncryptUtil.user_sex, mApplication.user_sex);
				SharedPreUtil.putStringValue(MainActivity.this,
						SharedPreEncryptUtil.authority, info.authority);
				SharedPreUtil.putStringValue(MainActivity.this,
						SharedPreEncryptUtil.real_phone, info.phone);
				if (main != null) {
					// if ((main.getName() == null || main.getName().equals(""))
					// && (main.getTel() == null || main.getTel().equals(
					// ""))) {
					main.setTel(mApplication.getUserphone());
					main.setName(mApplication.getRealName());

					// }
				}

				initView();
			} else {
			}

		}

		@Override
		public void onFailed(int status, String msg) {
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mUserBuild).getJson();
			return new Officail_InfoNet(context, json);
		}

	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tv_right:
			startActivity(new Intent(MainActivity.this,
					UnprocessedActivity.class));
			break;
		case R.id.iv_left:
			if (mApplication.isUidAndTokenNull()) {
				Intent intent = new Intent(this, LoginActivity.class);
				intent.putExtra(MainMsg.extra_login, MainMsg.INTENT_LOGIN);
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
			} else {
				mMenuDrawer.openMenu();
			}
			break;
		case R.id.layout_citycar:// 室内叫车
			viewpager.setCurrentItem(Value.VIEWID_SN);
			break;
		case R.id.layout_express:// 小件快递
			viewpager.setCurrentItem(Value.VIEWID_KJ);
			break;
		case R.id.layout_carpooling:// 拼车出行
			viewpager.setCurrentItem(Value.VIEWID_PC);
			break;
		case R.id.layout_charteredcar:// 包车出行
			viewpager.setCurrentItem(Value.VIEWID_BC);
			break;
		case R.id.personalDate:// 个人信息
			// if (!ClickFilter.filter())
			// return;
			// startActivity(new Intent(MainActivity.this,
			// PersonalDataActivity.class));
			break;
		case R.id.tv_address:// 常用地址
			if (!ClickFilter.filter())
				return;
			startActivity(new Intent(MainActivity.this, AddressActivity.class));
			break;
		case R.id.menu_message:
			if (!ClickFilter.filter())
				return;
			startActivity(new Intent(MainActivity.this, MessageActivity.class));
			break;
		case R.id.tv_set:// 设置
			if (!ClickFilter.filter())
				return;
			startActivity(new Intent(MainActivity.this, SetActivity.class));
			break;
		case R.id.tv_share:// 推荐有奖
			if (!ClickFilter.filter())
				return;
			startActivity(new Intent(MainActivity.this, RecommenActivity.class));
			break;
		case R.id.confirm:
			if (!ClickFilter.filter(1000))
				return;
			if (mApplication.getUid() != null && !mApplication.equals("")
					&& mApplication.getToken() != null
					&& !mApplication.getToken().equals("")) {
				onOrderSubmit(price);
			} else {
				Intent intent = new Intent(this, LoginActivity.class);
				intent.putExtra(MainMsg.extra_login, MainMsg.INTENT_LOGIN);
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
			}

			break;
		case R.id.tv_myorder:// 我的订单
			if (!ClickFilter.filter())
				return;
			startActivity(new Intent(MainActivity.this, MyOrderActivity.class));
			break;
		case R.id.menu_order:// 我的公务车订单
			if (!ClickFilter.filter())
				return;
			startActivity(new Intent(MainActivity.this,
					MyOrderOfficailActivity.class));
			break;
		case R.id.layout_coupon:// 优惠劵
			if (!ClickFilter.filter())
				return;
			startActivity(new Intent(MainActivity.this, CouponActivity.class));
			break;
		case R.id.layout_examine:
			if (!ClickFilter.filter())
				return;
			startActivity(new Intent(MainActivity.this,
					UnprocessedActivity.class));
			break;
		case R.id.tv_prompt:
			if (!ClickFilter.filter())
				return;
			// 跳转到订单详情界面,不能是支付状态
			if (list_ing != null
					&& list_ing.size() == 1
					&& Integer.parseInt(list_ing.get(0).getOrder_status()) != Value.ORDER_STATUS_OFFCAR) {
				Intent intent = new Intent(context, StartServiceActivity.class);
				intent.putExtra(OrderMsg.extra_type, 0);
				startActivityForResult(intent, requestCode);
			} else {
				startActivity(new Intent(MainActivity.this,
						MyOrderOfficailActivity.class));
			}

			break;
		case R.id.tv_kftel:
			v.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// 用intent启动拨打电话
					MainActivity.this.startActivity(new Intent(
							Intent.ACTION_DIAL, Uri
									.parse("tel:" + Value.TEL_KF)));
				}
			});
			break;
		case R.id.re_coupon:
			if (!ClickFilter.filter())
				return;
			if (mApplication.getUid() != null && !mApplication.equals("")
					&& mApplication.getToken() != null
					&& !mApplication.getToken().equals("")) {
				if (!confirm.isEnabled()) {
					// ToastUtil.showToast(context, R.string.isnull);
				} else if (list_available != null && !list_available.isEmpty()) {
					startActivityForResult(new Intent(this,
							UseCouponActivity.class).putExtra(
							UseCouponMsg.coupon_id, coupon_id),
							UseCouponMsg.requestCode);
				} else if (list_available != null && list_available.isEmpty()) {
					// ToastUtil.showToast(context, R.string.no_usbcoupon);
				}
			} else {
				Intent intent = new Intent(this, LoginActivity.class);
				intent.putExtra(MainMsg.extra_login, MainMsg.INTENT_LOGIN);
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
			}
			break;
		case R.id.layout_city_tel:
			// if (!ClickFilter.filter())
			// return;
			// startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"
			// + mCityCarFragment.xiadanTel)));
			break;
		case R.id.btn_exit:
			final MyAlertDailog dialog = new MyAlertDailog(this);
			dialog.setTitle(getString(R.string.mydailog_title));
			dialog.setContent(getString(R.string.mydailog_content_exit));
			dialog.setLeftButtonText(getString(R.string.mydailog_cancel));
			dialog.setRightButtonText(getString(R.string.mydailog_confirm));
			if (dialog != null && !dialog.isShowing()) {
				dialog.show();
			}
			dialog.setOnClickLeftListener(new onClickLeftListener() {
				@Override
				public void onClickLeft() {
					dialog.dismiss();
				}
			});
			dialog.setOnClickRightListener(new onClickRightListener() {

				@Override
				public void onClickRight() {
					dialog.dismiss();
					Intent intent = new Intent(context, LoginActivity.class);
					startActivity(intent);

				}
			});

			break;
		default:
			break;
		}
	}

	private void setButton(ImageView v, TextView tv) {
		switch (viewId) {
		case Value.VIEWID_SN:
			v.setImageResource(R.drawable.btn_city);
			btn_express.setImageResource(R.drawable.icon_down_nor);
			btn_carpooling.setImageResource(R.drawable.icon_down_nor);
			btn_charteredcar.setImageResource(R.drawable.icon_down_nor);
			break;
		case Value.VIEWID_KJ:
			v.setImageResource(R.drawable.btn_kj);
			btn_citycar.setImageResource(R.drawable.icon_down_nor);
			btn_carpooling.setImageResource(R.drawable.icon_down_nor);
			btn_charteredcar.setImageResource(R.drawable.icon_down_nor);
			break;
		case Value.VIEWID_PC:
			v.setImageResource(R.drawable.btn_pc);
			btn_citycar.setImageResource(R.drawable.icon_down_nor);
			btn_express.setImageResource(R.drawable.icon_down_nor);
			btn_charteredcar.setImageResource(R.drawable.icon_down_nor);
			break;
		case Value.VIEWID_BC:
			v.setImageResource(R.drawable.btn_bc);
			btn_citycar.setImageResource(R.drawable.icon_down_nor);
			btn_express.setImageResource(R.drawable.icon_down_nor);
			btn_carpooling.setImageResource(R.drawable.icon_down_nor);
			break;
		}
		setTextViewColor(tv);
		// if (!mOnMenuClickListenerList.isEmpty()) {
		// for (int i = 0; i < mOnMenuClickListenerList.size(); i++) {
		// mOnMenuClickListenerList.get(i).OnMenuClick();
		// }
		// }
		onContentFilling();

	}

	/**
	 * 设置，小件快递，拼车出行，包车出行的字体颜色
	 */
	private void setTextViewColor(TextView v) {
		if (currentTextView != null && currentTextView.getId() != v.getId()) {
			currentTextView.setTextColor(getResources().getColor(
					R.color.text_nor));
		}
		v.setTextColor(getResources().getColor(R.color.btn_pre));

		currentTextView = v;
	}

	/**
	 * 提交POPview
	 */
	private void onShowSubmitPopView(Officail_Price mOfficail_Price,
			boolean isTaxi) {
		// tv_price.setVisibility(View.VISIBLE);
		coupon_id = 0;
		for (OnPriceListener l : mOnPriceListener_list) {
			l.onPrice(mOfficail_Price, true, isTaxi);
		}
		// tv_price.setText(String.format(getString(R.string.coupon_deductible),
		// FormatUtil.onFormatPrice(price)));
		if (mOfficail_Price != null) {
			main.setEstimate_time(mOfficail_Price.getPriceDetail().getMinutes());
			this.price = mOfficail_Price.getPrice();
		} else {
			main.setEstimate_time(0);
			this.price = 0;
		}
		if (list_available != null && !list_available.isEmpty()) {
			// 降序
			Collections.sort(list_available);
			tv_coupon_deductible.setText("" + list_available.get(0).getSum());
			coupon_id = list_available.get(0).getId();
			confirm.setText(String.format(
					getString(R.string.confirm_price),
					FormatUtil.onFormatPrice(price
							- (list_available.get(0).getSum()) * 100)));
		} else {
			confirm.setEnabled(true);
			// tv_coupon_deductible.setText("0");
			// confirm.setText(String.format(getString(R.string.confirm_price),
			// FormatUtil.onFormatPrice(price)));
		}
		// if (viewId == Value.VIEWID_SN) {
		// tv_price.setVisibility(View.GONE);
		// confirm.setText(R.string.confirm_no_price);
		// }
		// View view = LayoutInflater.from(context).inflate(R.layout.pop_submit,
		// null);
		// final PopupWindow pop_submit = new PopupWindow(view,
		// LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		// pop_submit.setBackgroundDrawable(new BitmapDrawable());
		// pop_submit.setContentView(view);
		// pop_submit.setOutsideTouchable(false);
		// pop_submit.setFocusable(true);
		// pop_submit.showAtLocation(v, Gravity.CENTER, 0, 0);
		// TextView tv_price = (TextView) view.findViewById(R.id.tv_price);
		// tv_price.setText(FormatUtil.onFormatPrice(price));
		// final LinearLayout layout = (LinearLayout) view
		// .findViewById(R.id.layout);
		// Animation a = AnimationUtils.loadAnimation(context,
		// R.anim.dialog_in);
		// layout.startAnimation(a);
		// final ListView listview = (ListView)
		// view.findViewById(R.id.listview);
		// final AvailableCouponsAdapter mAvailableCouponsAdapter = new
		// AvailableCouponsAdapter(
		// this, list_available);
		// listview.setAdapter(mAvailableCouponsAdapter);
		// // 选择可用的优惠劵
		// final RelativeLayout layout_choice_available = (RelativeLayout) view
		// .findViewById(R.id.layout_choice_available);
		// final TextView tv_choice_available = (TextView) view
		// .findViewById(R.id.tv_choice_available);
		// // 选中的优惠劵
		// final TextView tv_selected = (TextView) view
		// .findViewById(R.id.tv_selected);
		// if (mAvailableCouponsAdapter.getCount() != 0) {
		// layout_choice_available.setVisibility(View.VISIBLE);
		// tv_choice_available.setVisibility(View.VISIBLE);
		// mAvailableCouponsAdapter.isSelected.put(0, true);
		// tv_selected.setText(String.format(context.getString(R.string.used_coupon),
		// list_available.get(0).getSum()));
		// coupon_id = list_available.get(0).getId();
		// }
		// listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
		// listview.setOnItemClickListener(new OnItemClickListener() {
		// @Override
		// public void onItemClick(AdapterView<?> arg0, View v, int position,
		// long arg3) {
		// if (list_available.get(position).getSum().equals("0")) {
		// tv_selected.setText(context.getString(R.string.no_used_coupon));
		// } else {
		// tv_selected.setText(String.format(context.getString(R.string.used_coupon),list_available.get(position).getSum()));
		// }
		// coupon_id = list_available.get(position).getId();
		// for (int i = 0; i < list_available.size(); i++) {
		// if (i == position) {
		// mAvailableCouponsAdapter.isSelected.put(i, true);
		// } else {
		// mAvailableCouponsAdapter.isSelected.put(i, false);
		// }
		// }
		// mAvailableCouponsAdapter.notifyDataSetInvalidated();
		// ViewHolder vHollder = (ViewHolder) v.getTag();
		// // 在每次获取点击的item时将对于的checkbox状态改变，同时修改map的值。
		// if (!vHollder.cb_available.isChecked()) {
		// vHollder.cb_available.toggle();
		// }
		// new Handler().postDelayed(new Runnable() {
		// @Override
		// public void run() {
		// listview.setVisibility(View.GONE);
		// layout_choice_available
		// .setBackgroundDrawable(context.getResources()
		// .getDrawable(R.drawable.bg_yhq2));
		// isOpenAvailable = false;
		// }
		// }, 10);
		//
		// }
		// });
		// layout_choice_available.setOnClickListener(new OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// if (list_available.size() == 0)
		// return;
		// isOpenAvailable = isOpenAvailable ? false : true;
		// if (isOpenAvailable) {
		// listview.setVisibility(View.VISIBLE);
		// mAvailableCouponsAdapter.notifyDataSetChanged();
		// layout_choice_available.setBackgroundDrawable(context
		// .getResources().getDrawable(R.drawable.bg_yhq1));
		// } else {
		// listview.setVisibility(View.GONE);
		// layout_choice_available.setBackgroundDrawable(context
		// .getResources().getDrawable(R.drawable.bg_yhq2));
		// }
		//
		// }
		// });
		// // 不允许
		// ((Button) view.findViewById(R.id.btn_no_allow))
		// .setOnClickListener(new OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// Animation a = AnimationUtils.loadAnimation(context,
		// R.anim.dialog_out);
		// layout.startAnimation(a);
		// a.setAnimationListener(new AnimationListener() {
		//
		// @Override
		// public void onAnimationStart(Animation anim) {
		// }
		//
		// @Override
		// public void onAnimationRepeat(Animation anim) {
		// }
		//
		// @Override
		// public void onAnimationEnd(Animation anim) {
		// new Handler().post(new Runnable() {
		// @Override
		// public void run() {
		// pop_submit.dismiss();
		// }
		// });
		// }
		// });
		// }
		// });
		// // 允许
		// ((Button) view.findViewById(R.id.btn_allow))
		// .setOnClickListener(new OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// // confirm.setClickable(false);
		// // 判断未完成订单网络是否加载成功
		// if (SharedPreUtil.getBooleanValue(MainActivity.this,
		// SharedPreEncryptUtil.isLoadOrder_ing, true)) {
		// getMyOrder_ING(true, 1);
		// } else {
		// onOrderSubmit(price);
		// }
		// Animation a = AnimationUtils.loadAnimation(context,
		// R.anim.dialog_out);
		// layout.startAnimation(a);
		// a.setAnimationListener(new AnimationListener() {
		//
		// @Override
		// public void onAnimationStart(Animation anim) {
		// }
		//
		// @Override
		// public void onAnimationRepeat(Animation anim) {
		// }
		//
		// @Override
		// public void onAnimationEnd(Animation anim) {
		// new Handler().post(new Runnable() {
		// @Override
		// public void run() {
		// pop_submit.dismiss();
		// }
		// });
		// }
		// });
		// }
		// });
	}

	/**
	 * 设置Elements，用于提交订单和获取价格
	 */
	public void setElements() {
		boolean isCity = (viewId == Value.VIEWID_SN) ? true : false;
		mOfficialOrderDetail = new OfficialOrderDetail();
		String name = main.getName();
		// 出发地
		Start start = new Start();
		//如果是自己下单
		if(main.getTel().trim().equals(mApplication.getUserphone())){
			int sex=1;
			try{sex=Integer.parseInt(mApplication.user_sex);}catch(Exception e){}	
			start.sex=sex;
		}
		//如果是提别人下单
		else{
			start.sex=-1;
		}
		start.name = new MyConvertToMsg().parseEmoji(context, name);
		start.address = main.getStartName();
		start.phone = main.getTel();
		Location mLocation = new Location();
		mLocation.lat = main.getStartLatitude();
		mLocation.lng = main.getStartLongitude();
		start.setLocation(mLocation);
		// 目的地
		End end = new End();
		end.address = main.getEndName();
		if (viewId == Value.VIEWID_KJ) {
			end.name = main.getName2();
			end.phone = main.getTel2();
		} else {
			// end.name ="";
			// end.phone = "";
		}
		Location mLocation2 = new Location();
		mLocation2.lat = main.getEndLatitude();
		mLocation2.lng = main.getEndLongitude();
		end.setLocation(mLocation2);
		// end.need_sms = main.getEnd_need_sms();
		mOfficialOrderDetail.start = start;
		mOfficialOrderDetail.end = end;

		Uinfo uinfo=new Uinfo();
		//传递自己的信息
		uinfo.name=mApplication.getRealName();
		uinfo.phone=mApplication.getUserphone();
		try{
			uinfo.sex=Integer.parseInt(mApplication.user_sex);
		}catch(Exception e){
			uinfo.sex=1;
		}
		mOfficialOrderDetail.uinfo=uinfo;
	}

	/**
	 * 提交订单，先默认不允许优惠劵
	 */
	public void onOrderSubmit(int price) {
		if (list_ing != null
				&& list_ing.size() >= Value.maxorder
				|| (viewId == Value.VIEWID_BC && (list_ing.size() + main
						.getCount_BC()) > Value.maxorder)) {
			ToastUtil.showToast(context, String.format(getResources()
					.getString(R.string.max_order), Value.maxorder));
			return;
		}
		int travel_type = 0;
		setElements();
		mOfficail_OrderSubmitBuild = new Officail_OrderSubmitBuild(this);
		mOfficail_OrderSubmitBuild.opuid = mApplication.getUid();
		mOfficail_OrderSubmitBuild.passenger_id = mApplication.getUid();
		// mOfficail_OrderSubmitBuild.passenger_name=mApplication.real_name;
		mOfficail_OrderSubmitBuild.purpose = main.getOwn_expense()==Value.NOOWN?main.getMessage_GW():"";
		OrderInfo mOrderInfo = new OrderInfo();
		mOrderInfo.vehicle_type_title = main.getVtypeTitle();
		mOrderInfo.vtype = Integer.parseInt(main.getVtype());
		mOrderInfo.seat_num = Integer.parseInt(main.getSeat_num());
		mOrderInfo.vlevel = Integer.parseInt(main.getLevelCar());
		mOrderInfo.appoint_time = DateFormat.onDateAdd_ss(main.getTime());
		mOrderInfo.round_trip =main.getOwn_expense()==Value.NOOWN?( main.getWf() ? Value.ROUND_TRIP :  Value.ROUND_TRIP_NO): Value.ROUND_TRIP_NO;
		mOrderInfo.vehicle_type_id = main.getVtypeId();
		mOrderInfo.driver_id = "";
		mOrderInfo.driver_name = "";
		mOrderInfo.estimate_cost = price;
		mOrderInfo.estimate_time = main.getEstimate_time();
		mOrderInfo.order_type = Value.ORDER_TYPE_GW;
		mOrderInfo.appoint_type = main.getTime().equals(Value.now_time) ? Value.TYPE_APPOINT_NO : Value.TYPE_APPOINT;
		mOrderInfo.own_expense = main.getOwn_expense();
		mOfficail_OrderSubmitBuild.other_info = mOrderInfo;
		mOfficail_OrderSubmitBuild.order_detail = mOfficialOrderDetail;

		mHandler.sendEmptyMessage(CONFIRM_CLICK);
		mOrderSubmitTask = new OrderSubmitTask(MainActivity.context,
				mOfficail_OrderSubmitBuild);
		mOrderSubmitTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (mMenuDrawer.isMenuVisible()) {
				mMenuDrawer.closeMenu();
			} else {
				if ((DateFormat.getTime() - mkeyTime) > 2000) {
					mkeyTime = DateFormat.getTime();
					ToastUtil.showToast(context, R.string.agin_exit);
				} else {
					finish();
				}

			}

			return true;

		}
		return false;
	}

	@Override
	public void startActivity(Intent intent) {
		super.startActivity(intent);
		overridePendingTransition(R.anim.base_slide_right_in,
				R.anim.base_slide_remain);
		Publisher.getInstance().removeOb(this);
	}

	public void startActivityForResult(Intent intent, int code) {
		super.startActivityForResult(intent, code);
		overridePendingTransition(R.anim.base_slide_right_in,
				R.anim.base_slide_remain);
		Publisher.getInstance().removeOb(this);
	}

	public static ArrayList<OnMenuClickListener> mOnMenuClickListenerList = new ArrayList<OnMenuClickListener>();
	public static OnMenuClickListener mOnMenuClickListener;

	/**
	 * 自定义下面菜单点击监听
	 */
	public interface OnMenuClickListener {
		public void OnMenuClick();
	}

	public static void setOnMenuClickListener(
			OnMenuClickListener hOnMenuClickListener) {
		mOnMenuClickListenerList.add(hOnMenuClickListener);
	}

	public void removeOnMenuClickListener(
			OnMenuClickListener hOnMenuClickListener) {
		mOnMenuClickListenerList.remove(hOnMenuClickListener);
	}

	@Override
	public void onPopViewState(boolean isOpen) {
		if (isOpen) {
			pop_background.setVisibility(View.VISIBLE);
		} else {
			pop_background.setVisibility(View.GONE);
		}

	}

	@Override
	public void onWheelCustomState(boolean isOpen) {
		if (isOpen) {
			pop_background.setVisibility(View.VISIBLE);
		} else {
			pop_background.setVisibility(View.GONE);
		}
	}

	@Override
	public void onAddressPopViewState(boolean isOpen) {
		if (isOpen) {
			pop_background.setVisibility(View.VISIBLE);
		} else {
			pop_background.setVisibility(View.GONE);
		}
	}

	@Override
	protected void onDestroy() {
		loaddialog = null;
		// mCityCarFragment.removeOnTelInterfaceListener(this);
		DatePicker.removeOnPoPViewStateListener(this);
		WheelCustom.removeOnWheelCustomStateListener(this);
		CollecteAddressPop.removeOnPhotosPoPViewStateListener(this);
		if (mUserTask != null
				&& mUserTask.getStatus() != AsyncTask.Status.FINISHED)
			mUserTask.cancel(true);
		if (mCouponUsableTask != null
				&& mCouponUsableTask.getStatus() != AsyncTask.Status.FINISHED)
			mCouponUsableTask.cancel(true);
		if (mOrderSubmitTask != null
				&& mOrderSubmitTask.getStatus() != AsyncTask.Status.FINISHED)
			mOrderSubmitTask.cancel(true);
		if (mPriceTask != null
				&& mPriceTask.getStatus() != AsyncTask.Status.FINISHED)
			mPriceTask.cancel(true);
		Publisher.getInstance().removeOb(this);
		if (mApplication != null)
			mApplication.removeOnLocationResultListener(this);
		super.onDestroy();
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onPageSelected(int position) {
		layout_price_comfirm.setVisibility(View.VISIBLE);
		layout_city_tel.setVisibility(View.GONE);
		viewId = position;
		switch (position) {
		case Value.VIEWID_SN:
			if (!mMyOnPageScrolledListener_list.isEmpty()) {
				for (int i = 0; i < mMyOnPageScrolledListener_list.size(); i++) {
					mMyOnPageScrolledListener_list.get(i).onPageScrolled(
							Value.VIEWID_SN);
				}
			}
			setButton(btn_citycar, tv_citycar);
			if (mApplication.getUid() != null && !mApplication.equals("")
					&& mApplication.getToken() != null
					&& !mApplication.getToken().equals("")) {
				mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
			} else {
				mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_NONE);
			}
			break;
		case Value.VIEWID_KJ:
			if (!mMyOnPageScrolledListener_list.isEmpty()) {
				for (int i = 0; i < mMyOnPageScrolledListener_list.size(); i++) {
					mMyOnPageScrolledListener_list.get(i).onPageScrolled(
							Value.VIEWID_KJ);
				}
			}
			setButton(btn_express, tv_express);
			mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_NONE);
			break;
		case Value.VIEWID_PC:
			if (!mMyOnPageScrolledListener_list.isEmpty()) {
				for (int i = 0; i < mMyOnPageScrolledListener_list.size(); i++) {
					mMyOnPageScrolledListener_list.get(i).onPageScrolled(
							Value.VIEWID_PC);
				}
			}
			setButton(btn_carpooling, tv_carpooling);
			mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_NONE);
			break;
		case Value.VIEWID_BC:
			if (!mMyOnPageScrolledListener_list.isEmpty()) {
				for (int i = 0; i < mMyOnPageScrolledListener_list.size(); i++) {
					mMyOnPageScrolledListener_list.get(i).onPageScrolled(
							Value.VIEWID_BC);
				}
			}
			setButton(btn_charteredcar, tv_charteredcar);
			mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_NONE);
			break;
		}
	}

	/**
	 * 主界面内容填写监听方法
	 */
	@Override
	public void onContentFilling() {
		switch (viewId) {
		// case Value.VIEWID_SN:
		case Value.VIEWID_GW:
			if (isNull(main.getTime())
					// && isNull(main.getName())
					&& isNull(main.getTel()) && isNull(main.getStartName())
					&& isNull(main.getStartLatitude())
					&& isNull(main.getStartLongitude())
					&& isNull(main.getEndName())
					&& isNull(main.getEndLatitude())
					&& isNull(main.getEndLongitude())
					&& isNull(main.getLevelCar()) && isNull(main.getSeat_num())
					&& isNull(main.getVtype())) {
				setConfirm(true);
				getPrice();
			} else {
				setConfirm(false);
			}
			break;
		case Value.VIEWID_KJ:// 小件快递
			if (isNull(main.getTime())
					// && isNull(main.getName())
					&& main.getIsCBclause() && isNull(main.getTel())
					&& isNull(main.getStartName())
					&& isNull(main.getStartLatitude())
					&& isNull(main.getStartLongitude())
					&& isNull(main.getName2()) && isNull(main.getTel2())
					&& isNull(main.getEndName())
					&& isNull(main.getEndLatitude())
					&& isNull(main.getEndLongitude())) {
				setConfirm(true);
				getPrice();
			} else {
				setConfirm(false);
			}
			break;
		case Value.VIEWID_PC:// 拼车出行
			if (isNull(main.getTime())
					// && isNull(main.getName())
					&& isNull(main.getTel()) && isNull(main.getStartName())
					&& isNull(main.getStartLatitude())
					&& isNull(main.getStartLongitude())
					&& isNull(main.getEndName())
					&& isNull(main.getEndLatitude())
					&& isNull(main.getEndLongitude())
					&& isNull(main.getCount())) {
				setConfirm(true);
				getPrice();
			} else {
				setConfirm(false);

			}
			break;
		case Value.VIEWID_BC:// 包车出行
			if (isNull(main.getTime())
					// && isNull(main.getName())
					&& isNull(main.getTel()) && isNull(main.getStartName())
					&& isNull(main.getStartLatitude())
					&& isNull(main.getStartLongitude())
					&& isNull(main.getEndName())
					&& isNull(main.getEndLatitude())
					&& isNull(main.getEndLongitude())
					&& isNull(main.getCount_BC())) {
				setConfirm(true);
				getPrice();
			} else {
				setConfirm(false);
			}
			break;
		}

	}

	public boolean isNull(String s) {
		if (s != null && !s.equals(""))
			return true;
		return false;
	}

	public boolean isNull(Double s) {
		if (s != null && s != 0)
			return true;
		return false;
	}

	public boolean isNull(Integer s) {
		if (s != null && s != 0)
			return true;
		return false;
	}

	/**
	 * 获取价格
	 * 
	 */
	private class PriceTask extends BaseAsyncTask {

		private Officail_PriceBuild mOfficail_PriceBuild;

		public PriceTask(Activity context,
				Officail_PriceBuild mOfficail_PriceBuild) {
			super(context, false);
			isPrice = true;
			this.mOfficail_PriceBuild = mOfficail_PriceBuild;
		}

		@Override
		public void onSuccess(Object object) {
			mHandler.sendEmptyMessage(DIALOG_DISMISS);
			if (object != null) {
				Officail_Price price = (Officail_Price) object;
				onShowSubmitPopView(price, false);

			} else {
				if (viewId != Value.VIEWID_SN) {
					ToastUtil.showToast(context,
							getResources().getString(R.string.price_error));
					setConfirm(false);
				}
			}

		}

		@Override
		public void onFailed(int status, String msg) {
			mHandler.sendEmptyMessage(DIALOG_DISMISS);
			try {
				JSONObject js = new JSONObject(msg);
				ToastUtil.showToast(context, js.get("message").toString());
				for (OnPriceListener l : mOnPriceListener_list) {
					l.onPrice(null, false, false);
				}
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			setConfirm(false);
			// if (viewId != Value.VIEWID_SN) {
			// if (status == -10) {
			// Price mPrice = (Price) new JsonBuild().getData(Price.class,
			// msg);
			// final Price.Note note = mPrice.getNote();
			// //旧版本的没用该路线
			// if (note == null) {
			// final MyAlertDailog mydialog = new MyAlertDailog(
			// context);
			// mydialog.setTitle(context
			// .getString(R.string.mydailog_title));
			// mydialog.setContent(context
			// .getString(R.string.price_no));
			// mydialog.setSingle(context
			// .getString(R.string.mydailog_know));
			// mydialog.setOnClickSingleListener(new onClickSingleListener() {
			// @Override
			// public void onClickSingle() {
			// mydialog.dismiss();
			// }
			// });
			// mydialog.show();
			// setConfirm(false);
			// } else {
			// final MyAlertDailog mydialog = new MyAlertDailog(
			// context);
			// final MyLineNotDialog mylinedialog=new MyLineNotDialog(context);
			// mydialog.setTitle(context
			// .getString(R.string.mydailog_title));
			//
			// // 切换到城际包车
			// if (note.getPrice() != null
			// && !note.getPrice().equals("")) {
			// mylinedialog.setContent(note.getMsg());
			// mylinedialog.setContent2(note.getPrice());
			// mylinedialog.setLeftButtonText(context
			// .getString(R.string.mydailog_besides));
			// mylinedialog.setRightButtonText(context
			// .getString(R.string.text_charteredcar));
			// mylinedialog.setOnLineClickLeftListener(new
			// OnLineClickLeftListener() {
			// @Override
			// public void onLineClickLeft() {
			// mylinedialog.dismiss();
			// }
			// });
			// mylinedialog.setOnLineClickRightListener(new
			// OnLineClickRightListener() {
			// @Override
			// public void onLineClickRight() {
			// mylinedialog.dismiss();
			// main.setMessage_BC(main.getMessage_PC());
			// viewpager.setCurrentItem(Value.VIEWID_BC);
			// }
			// });
			// mylinedialog.show();
			// }
			// // 呼叫客服或者旧版本的没用该路线
			// else {
			// //呼叫客服
			// if(note.getLine_id()!=null&&!note.getLine_id().equals("")){
			// mylinedialog.setContent(note.getMsg());
			// mylinedialog.setLeftButtonText(context
			// .getString(R.string.mydailog_besides));
			// mylinedialog.setRightButtonText(getString(R.string.mydailog_telkf));
			// mylinedialog.setOnLineClickLeftListener(new
			// OnLineClickLeftListener() {
			// @Override
			// public void onLineClickLeft() {
			// mylinedialog.dismiss();
			// }
			// });
			// mylinedialog.setOnLineClickRightListener(new
			// OnLineClickRightListener() {
			// @Override
			// public void onLineClickRight() {
			// mylinedialog.dismiss();
			// Tel.onTel_KF(context, note.getLine_id());
			// }
			// });
			// mylinedialog.show();
			// }
			// //旧版本的没用该路线
			// else{
			// mydialog.setTitle(context
			// .getString(R.string.mydailog_title));
			// mydialog.setContent(context
			// .getString(R.string.price_no));
			// mydialog.setSingle(context
			// .getString(R.string.mydailog_know));
			// mydialog.setOnClickSingleListener(new onClickSingleListener() {
			// @Override
			// public void onClickSingle() {
			// mydialog.dismiss();
			// }
			// });
			// mydialog.show();
			// }
			//
			// }
			// setConfirm(false);
			// }
			//
			// } else {
			// ToastUtil.showToast(context,
			// getResources().getString(R.string.price_error));
			// setConfirm(false);
			// }
			// }
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOfficail_PriceBuild)
					.getJson();
			return new Officail_PriceNet(context, json);
		}
	}

	/**
	 * 可用优惠劵
	 * 
	 */
	private class CouponUsableTask extends BaseAsyncTask {

		private CouponUsableBulid mCouponUsable;

		private int price;

		public CouponUsableTask(Activity context, CouponUsableBulid mCouponUsable,
				int price) {
			super(context, false);
			this.mCouponUsable = mCouponUsable;
			setIsReturnString(true);
			this.price = price;
		}

		@Override
		public void onSuccess(Object object) {
			if (object != null) {
				CouponList mCouponList = new CouponList();
				JSONArray ja_CouponList;
				try {
					List<Coupons> coupons_list = new ArrayList<Coupons>();
					JSONObject json = new JSONObject((String) object);
					ja_CouponList = json.getJSONArray(CouponMsg.msg_coupons);
					for (int i = 0; i < ja_CouponList.length(); i++) {
						Coupons mCoupons = new Coupons();
						JSONObject jo = new JSONObject(ja_CouponList.get(i)
								.toString());
						mCoupons.setId(Integer.parseInt(jo
								.getString(CouponMsg.msg_id)));
						mCoupons.setSum(Integer.parseInt(jo
								.getString(CouponMsg.msg_sum)));
						mCoupons.setExpire_time(jo
								.getString(CouponMsg.msg_expire_time));
						JSONObject jo_metadata = new JSONObject(
								jo.getString(CouponMsg.msg_metadata));
						Metadata mMetadata = new Metadata();

						JSONArray ja_line = new JSONArray(
								jo_metadata.getString(CouponMsg.msg_usableline));
						List<String> list_line = new ArrayList<String>();
						for (int j = 0; j < ja_line.length(); j++) {
							String str_line = ja_line.get(j).toString();
							list_line.add(str_line);
						}
						mMetadata.setUsableline(list_line);

						mMetadata.setUsabletype(jo_metadata
								.getString(CouponMsg.msg_usabletype));
						mMetadata.setUsableorder(jo_metadata
								.getString(CouponMsg.msg_usableorder));
						mMetadata.setUsabletime(jo_metadata
								.getString(CouponMsg.msg_usabletime));
						mCoupons.setMetadata(mMetadata);
						coupons_list.add(mCoupons);
					}
					mCouponList.setCouponList(coupons_list);
				} catch (JSONException e) {
				}
				list_available.clear();
				if (mCouponList != null && mCouponList.getCouponList() != null
						&& !mCouponList.getCouponList().isEmpty()) {
					list_available.addAll(mCouponList.getCouponList());
					onShowSubmitPopView(null, false);
				} else {
					onShowSubmitPopView(null, false);
				}
				mHandler.sendEmptyMessage(DIALOG_DISMISS);
			}
		}

		@Override
		public void onFailed(int status, String msg) {
			list_available.clear();
			mHandler.sendEmptyMessage(DIALOG_DISMISS);
			onShowSubmitPopView(null, false);
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mCouponUsable).getJson();
			return new CouponUsableNet(context, json);
		}
	}

	/**
	 * 订单提交
	 * 
	 */
	public class OrderSubmitTask extends BaseAsyncTask {

		private Officail_OrderSubmitBuild mOfficail_OrderSubmitBuild;
		private Activity context;

		public OrderSubmitTask(Activity context,
				Officail_OrderSubmitBuild mOfficail_OrderSubmitBuild) {
			super(context);
			setLoadCancel(false);
			this.context = context;
			this.mOfficail_OrderSubmitBuild = mOfficail_OrderSubmitBuild;
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOfficail_OrderSubmitBuild)
					.getJson();
			return new Officail_OrderSubmitNet(context, json);
		}

		@Override
		public void onSuccess(Object object) {
			if (object != null) {
				// TODO Auto-generated method stub
				Officail_OrderSubmit mOfficail_OrderSubmit = (Officail_OrderSubmit) object;
				LogUtils.e("",
						"提交成功,订单Id为：" + mOfficail_OrderSubmit.getOrder_id());
				onWriteDB_ing(mOfficail_OrderSubmit.getOrder_id());
				mHandler.sendEmptyMessage(CONFIRM_NOCLICK);
			} else {
				ToastUtil.showToast(context,
						getResources().getString(R.string.no_network));
				mHandler.sendEmptyMessage(CONFIRM_NOCLICK);
			}

		}

		@Override
		public void onFailed(int status, String msg) {
			if (status == -2) {
				ToastUtil.showToast(context,
						getResources().getString(R.string.time_erro));
			} else {
				// TODO Auto-generated method stub
				ToastUtil.showToast(context,
						getResources().getString(R.string.no_network));
			}

			mHandler.sendEmptyMessage(CONFIRM_NOCLICK);
		}
	}

	/**
	 * 写入进行中的订单数据
	 */
	private void onWriteDB_ing(String orderid) {
		OfficialOrderList mOfficialOrderList = new OfficialOrderList();
		// mOfficialOrderList.setId("");
		mOfficialOrderList.setTcId(main.getTc_id());
		mOfficialOrderList.setOrder_id(orderid);
		mOfficialOrderList.setAppoint_time(DateFormat.onDateAdd_ss(main
				.getTime()));
		mOfficialOrderList.setOrder_time(DateFormat.onDateAdd_ss(DateFormat
				.getCurrentTime()));
		mOfficialOrderList.setLine_id(line_id);
		// mOfficialOrderList.setCoupon_id(String.valueOf(coupon_id));
		mOfficialOrderList.setOrder_status((Value.ORDER_STATUS_UNTREATED) + "");// 未处理
		mOfficialOrderList.setPrice(price + "");
		if (list_available != null && !list_available.isEmpty()) {
			Discount mDiscount = new Discount();
			for (int z = 0; z < list_available.size(); z++) {
				if (list_available.get(z).getId() == coupon_id) {
					mDiscount.setSum((list_available.get(z).getSum()));
					mOfficialOrderList.setDiscount(mDiscount);
					mOfficialOrderList.setTotal_price((price - (list_available
							.get(z).getSum()) * 100) + "");
					break;
				} else {
					mOfficialOrderList.setTotal_price(price + "");
				}
			}
		} else {
			mOfficialOrderList.setTotal_price(price + "");
		}

		mOfficialOrderList.setValuate_status(String
				.valueOf(Value.VALUATE_STATUS_NO));// 待评价
		// switch (viewId) {
		// case Value.VIEWID_KJ:
		// mOfficialOrderList.setMessage(main.getMessage_KJ());
		// break;
		// case Value.VIEWID_PC:
		// mOfficialOrderList.setMessage(main.getMessage_PC());
		// break;
		// case Value.VIEWID_BC:
		// mOfficialOrderList.setMessage(main.getMessage_BC());
		// break;
		//
		// }
		mOfficialOrderList.setMessage(main.getMessage_GW());
		Start mStart = new Start();
		// 由于elements目前只提交一个，包车后台会拆分，所以地址都公用数组0的
		mStart.setAddress(mOfficialOrderDetail.getStart().getAddress());
		mStart.setName(mOfficialOrderDetail.getStart().getName());
		mStart.setPhone(mOfficialOrderDetail.getStart().getPhone());
		Location mLocation_start = new Location();
		mLocation_start.setLat(mOfficialOrderDetail.getStart().getLocation()
				.getLat());
		mLocation_start.setLng(mOfficialOrderDetail.getStart().getLocation()
				.getLng());
		mStart.setLocation(mLocation_start);
		End end = new End();
		end.setAddress(mOfficialOrderDetail.getEnd().getAddress());
		end.setName(mOfficialOrderDetail.getEnd().getName());
		end.setPhone(mOfficialOrderDetail.getEnd().getPhone());
		Location mLocation_end = new Location();
		mLocation_end.setLat(mOfficialOrderDetail.getEnd().getLocation()
				.getLat());
		mLocation_end.setLng(mOfficialOrderDetail.getEnd().getLocation()
				.getLng());
		end.setLocation(mLocation_end);
		mOfficialOrderDetail.setStart(mStart);
		mOfficialOrderDetail.setEnd(end);
		mOfficialOrderList.setOrderDetail(mOfficialOrderDetail);
		mOfficialOrderList.setOrderInfo(mOfficail_OrderSubmitBuild.other_info);
		mOfficialOrderList.purpose = mOfficail_OrderSubmitBuild.purpose;
		mOfficialOrderList.setAudit_status(Value.STATUS_AUDIT_NO);// 设置为待审核
		db_myorder.onWriteDB(context, mOfficialOrderList);
		// boolean isCity = (viewId == Value.VIEWID_SN) ? true : false;
		boolean isCity = false;
		db_address.onWrite(main.getStartName(isCity),
				main.getStartCity(isCity), main.getStartAddress(isCity),
				main.getStartLongitude(isCity), main.getStartLatitude(isCity),
				Value.ADDRESS_TYPE_HISTORY);
		db_address.onWrite(main.getEndName(isCity), main.getEndCity(isCity),
				main.getEndAddress(isCity), main.getEndLongitude(isCity),
				main.getEndLatitude(isCity), Value.ADDRESS_TYPE_HISTORY);
		// // 存储在线消息数据
		// JmsgDB db_jmsg = new JmsgDB(context);
		// db_jmsg.onWrite(mOfficialOrderList.getOrder_id(),
		// mOfficialOrderList.getOrder_time(), GMsg.ONLINE_XIADAN, null);
		if (mOfficail_OrderSubmitBuild.other_info.getOwn_expense() == Value.OWN) {
			mOfficialOrderList.setAudit_status(Value.STATUS_AUDIT_PASS);// 设置为审核通过
			mOfficialOrderList.setOwn_expense(Value.OWN + "");
			mOfficialOrderList.setAppoint_type(mOfficail_OrderSubmitBuild.other_info.appoint_type+"");
			mOfficialOrderList.setOrder_type(mOfficialOrderList.getOrderInfo()
					.getOrderType() + "");
			mOfficialOrderList.setRound_trip(mOfficail_OrderSubmitBuild.other_info.round_trip);
			db_myordering.onWriteDB_ing(context, mOfficialOrderList);
			db_myorder.onWriteDB(context, mOfficialOrderList);
			Intent intent = new Intent(context, StartServiceActivity.class);
			intent.putExtra(OrderMsg.extra_type, 0);
			startActivityForResult(intent, requestCode);
		} else {
			OrderUnprocessed.setOrder(mOfficialOrderList, orderid);
			context.startActivityForResult(
					new Intent(context, OrderUnprocessed.class).putExtra(
							ExamineMsg.EXAMINE_TYPE, ExamineMsg.TYPE_OF)
							.putExtra(ExamineMsg.EXAMINE_STATUS,
									ExamineMsg.STATUS_NO), requestCode);
		}

	}

	@Override
	public synchronized void onNotify(int type, JSONObject jb,
			Msgs.Data msgs_data) {
		switch (type) {
		case GMsg.OFFLINE:
			if (mApplication.getUid() != null && !mApplication.equals("")
					&& mApplication.getToken() != null
					&& !mApplication.getToken().equals("")) {
				if (mApplication != null) {
					MyOrderTask.getInstance(context, MyOrderActivity.num_ing,
							Value.TYPE_ING,Value.OWNALL, MyOrderTask.TYPE_REFRESH)
							.setOnOrderFinishListener(this);
				}
			}
			break;
		case GMsg.OFFICAIL_ONLINE_PAIDAN:
			getMyOrder_ING(false, null);
			ToastUtil.showToast(context, R.string.msg_paidan);
			break;
		case GMsg.OFFICAIL_ONLINE_CANCEL:
		case GMsg.ONLINE_KF_CANCEL:
			getMyOrder_ING(false, null);
			MessageDialog.onKfCancelDialog(context, msgs_data);
			break;
		case GMsg.OFFICAIL_ONLINE_GAIPAI:
		case GMsg.ONLINE_KF_GAIPAIL:
			getMyOrder_ING(false, null);
			MessageDialog.onGaipaiDialog(context, msgs_data);
			break;
		case GMsg.OFFICAIL_ONLINE_ONCAR:
			getMyOrder_ING(false, null);
			ToastUtil.showToast(context, R.string.msg_oncar);
			break;
		case GMsg.OFFICAIL_ONLINE_OFFCAR:// 下车，待支付
			getMyOrder_ING(false, null);
			MessageDialog.onOffCarDialog(context, msgs_data);
			break;
		case GMsg.ONLINE_FINISH:
		case GMsg.OFFICAIL_ONLINE_FINISH:
			getMyOrder_ING(false, null);
			// ToastUtil.showToast(context, R.string.msg_finish);
			break;
		case GMsg.ONLINE_BUSY:
			MessageDialog.onBusyDialog(context, msgs_data);
			break;
		case GMsg.ONLINE_RELOGIN:
			MessageDialog.onReloginDialog(context);
			break;
		case GMsg.ONLINE_BG_ORDER:
			getMyOrder_ING(false, null);
			break;
		case GMsg.ONLINE_KF_CHANGE:
			ToastUtil.showToast(context, R.string.toast_change);
			MyOrderTask.getInstance(context, MyOrderActivity.num_ing,
					Value.TYPE_ING,Value.OWNALL, MyOrderTask.TYPE_REFRESH)
					.setOnOrderFinishListener(this);
			break;
		case GMsg.ONLINE_UNPROCESSED_RESULT:
			MyOrderTask.getInstance(context, MyOrderActivity.num_ing,
					Value.TYPE_ING,Value.OWNALL, MyOrderTask.TYPE_REFRESH)
					.setOnOrderFinishListener(this);
			MessageDialog.onUnprocessed(context, msgs_data);
			break;
		case GMsg.OFFICAIL_ONLINE_ROUND_TRIP:
			MessageDialog.onRoundTripDialog(context, msgs_data, false);
			break;
		case GMsg.OFFICAIL_AA:
			MessageDialog.onAADialog(context, msgs_data);
			break;		
		}

	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		for (MyOnTouchListener listener : onTouchListeners) {
			listener.onTouch(ev);
		}
		return super.dispatchTouchEvent(ev);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// 由于MianActivity设置了单利，所以，onActivityResult很容易被调用，要设置下限制。
		if (this.requestCode == requestCode && this.resultCode == resultCode) {
			setConfirm(false);
			main.onRestoreAttribute();
			if (mOnActivityResultListener != null) {
				mOnActivityResultListener.OnActivityResulFinish();
			}
			isLocation = false;
			mApplication.onStartLocation();
			initView();
			switch (viewId) {
			case Value.VIEWID_SN:
				if (!mMyOnPageScrolledListener_list.isEmpty()) {
					for (int i = 0; i < mMyOnPageScrolledListener_list.size(); i++) {
						mMyOnPageScrolledListener_list.get(i).onPageScrolled(
								Value.VIEWID_SN);
					}
				}
				break;
			case Value.VIEWID_KJ:
				if (!mMyOnPageScrolledListener_list.isEmpty()) {
					for (int i = 0; i < mMyOnPageScrolledListener_list.size(); i++) {
						mMyOnPageScrolledListener_list.get(i).onPageScrolled(
								Value.VIEWID_KJ);
					}
				}
				break;
			case Value.VIEWID_PC:
				if (!mMyOnPageScrolledListener_list.isEmpty()) {
					for (int i = 0; i < mMyOnPageScrolledListener_list.size(); i++) {
						mMyOnPageScrolledListener_list.get(i).onPageScrolled(
								Value.VIEWID_PC);
					}
				}
				break;
			case Value.VIEWID_BC:
				if (!mMyOnPageScrolledListener_list.isEmpty()) {
					for (int i = 0; i < mMyOnPageScrolledListener_list.size(); i++) {
						mMyOnPageScrolledListener_list.get(i).onPageScrolled(
								Value.VIEWID_BC);
					}
				}
				break;
			}

		} else if (UseCouponMsg.requestCode == requestCode
				&& UseCouponMsg.resultCode == resultCode) {
			if (data != null) {
				tv_coupon_deductible.setText(""
						+ data.getExtras().getInt(UseCouponMsg.sum));
				coupon_id = data.getExtras().getInt(UseCouponMsg.coupon_id);
				if (viewId != Value.VIEWID_SN) {
					confirm.setText(String.format(
							getString(R.string.confirm_price),
							FormatUtil.onFormatPrice(price
									- (data.getExtras()
											.getInt(UseCouponMsg.sum)) * 100)));
				}
			}
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	@Override
	public void onLocationResult(BDLocation location) {
		if (!isLocation && location != null && location.getCity() != null
				&& location.getProvince() != null) {
			if (main.getStartName() == null || main.getStartName().equals("")) {
				main.setStartName(location.getCity()
						+ " "
						+ location.getAddrStr().replace(
								getString(R.string.china)
										+ location.getProvince()
										+ location.getCity(), ""));
				main.setStartName(
						location.getCity()
								+ " "
								+ location.getAddrStr().replace(
										getString(R.string.china)
												+ location.getProvince()
												+ location.getCity(), ""), true);
				main.setStartCity(location.getCity());
				main.setStartCity(location.getCity(), true);
				String address = location.getAddrStr();
				if (address.startsWith("中国")) {
					address = address.substring(2, address.length());
				}
				main.setStartAddress(address);
				main.setStartAddress(address, true);
				main.setStartLongitude(location.getLongitude());
				main.setStartLongitude(location.getLongitude(), true);
				main.setStartLatitude(location.getLatitude());
				main.setStartLatitude(location.getLatitude(), true);
				if (!mOfficialFragment.onLocationResult()) {
					isLocation = true;
					if (isLoadFinish) {
						getCityNotOpened(true);
					}
					mApplication.onStopLocation();
				}

			}
		}

	}

	@Override
	public void onLocationResult(ReverseGeoCodeResult result) {
		if (!isLocation && result != null
				&& result.getAddressDetail().city != null
				&& result.getAddressDetail().province != null) {
			if (main.getStartName() == null || main.getStartName().equals("")) {
				String city = result.getAddressDetail().city;
				String province = result.getAddressDetail().province;
				String address = result.getAddress();
				if (address.startsWith("中国")) {
					address = address.substring(2, address.length());
				}
				main.setStartName(city + " "
						+ address.replace(province + city, ""));
				main.setStartName(
						city + " " + address.replace(province + city, ""), true);
				main.setStartCity(city);
				main.setStartCity(city, true);
				main.setStartAddress(address);
				main.setStartAddress(address, true);
				main.setStartLongitude(result.getLocation().longitude);
				main.setStartLongitude(result.getLocation().longitude, true);
				main.setStartLatitude(result.getLocation().latitude);
				main.setStartLatitude(result.getLocation().latitude, true);
				if (!mOfficialFragment.onLocationResult()) {
					isLocation = true;
					if (isLoadFinish) {
						getCityNotOpened(true);
					}
					mApplication.onStopLocation();
				}

			}
		}
	}

	@Override
	public void onLocationFail(boolean isnet) {
		if (!isLocationFail && isnet) {
			final MyAlertDailog dialog = new MyAlertDailog(this);
			dialog.setTitle(getString(R.string.mydailog_title));
			dialog.setContent(getString(R.string.mydailog_content_locationfail));
			dialog.setSingle(getString(R.string.mydailog_know));
			if (dialog != null && !dialog.isShowing()) {
				dialog.show();
			}
			dialog.setOnClickSingleListener(new onClickSingleListener() {
				@Override
				public void onClickSingle() {
					dialog.dismiss();
				}
			});
		} else if (!isLocationFail && !isnet) {
			final MyAlertDailog dialog = new MyAlertDailog(this);
			dialog.setTitle(getString(R.string.mydailog_title));
			dialog.setContent(getString(R.string.mydailog_content_nonet));
			dialog.setLeftButtonText(getString(R.string.mydailog_cancel));
			dialog.setRightButtonText(getString(R.string.mydailog_set));
			if (dialog != null && !dialog.isShowing()) {
				// dialog.show();
			}
			dialog.setOnClickLeftListener(new onClickLeftListener() {

				@Override
				public void onClickLeft() {
					dialog.dismiss();
				}
			});
			dialog.setOnClickRightListener(new onClickRightListener() {

				@Override
				public void onClickRight() {
					Intent intent = null;
					/** 判断手机系统的版本 即API大于10 就是3.0或以上版本及魅族手机 */
					if (android.os.Build.VERSION.SDK_INT > 10
							&& !android.os.Build.MANUFACTURER.equals("Meizu")) {
						intent = new Intent(
								android.provider.Settings.ACTION_WIRELESS_SETTINGS);
					} else {
						intent = new Intent();
						ComponentName component = new ComponentName(
								"com.android.settings",
								"com.android.settings.WirelessSettings");
						intent.setComponent(component);
						intent.setAction("android.intent.action.VIEW");
					}
					context.startActivity(intent);
				}
			});

		}
		isLocationFail = true;

	}

	public void finish() {
		// if (mApplication.getUid() != null &&
		// !mApplication.getUid().equals("")) {
		// LogUtils.uploadLog(context, mApplication.getUid(), LOG_PATH);
		// }
		WakeLockUtil.releaseWakeLock();
		if (mApplication != null) {
			mApplication.loctionCity = "";
			mApplication.onStopLocation();
		}
		LoginService.SDKlogin = false;
		mApplication.isFirstActivity = true;
		isLocation = false;
		if (main != null) {
			main.setNull();
		}
		super.finish();
	}

	Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case DIALOG_SHOW:
				if (!isNoLoad) {
					if (loaddialog != null && !loaddialog.isShowing()) {
						loaddialog.show();
					}
				}
				isNoLoad = false;
				break;
			case DIALOG_DISMISS:
				if (loaddialog != null) {
					loaddialog.onDismiss();
					isPrice = false;
				}
				break;
			case CONFIRM_CLICK:
				setConfirm(false);
				break;
			case CONFIRM_NOCLICK:
				setConfirm(true);
				break;
			case PROMPT_VISIBLE:
				tv_prompt.setVisibility(View.VISIBLE);
				break;
			case PROMPT_GONE:
				tv_prompt.setVisibility(View.GONE);
				break;
			}

		}
	};

	@Override
	public void onTelInterface(boolean isTel) {
		isTelInteface = isTel;
		setTelInterface();
	}

	public void setTelInterface() {
		if (isTelInteface) {
			if (viewId == Value.VIEWID_SN) {
				layout_price_comfirm.setVisibility(View.GONE);
				layout_city_tel.setVisibility(View.VISIBLE);
			}
		} else {
			layout_price_comfirm.setVisibility(View.VISIBLE);
			layout_city_tel.setVisibility(View.GONE);
		}
	}

	/**
	 * 设置确定按钮的灰化
	 */
	public void setConfirm(boolean isEnabled) {
		if (isEnabled) {
			confirm.setEnabled(true);
			// confirm.setTextColor(context.getResources().getColor(R.color.white));
		} else {
			confirm.setEnabled(false);
			// confirm.setTextColor(context.getResources().getColor(
			// R.color.text_enabled));
			confirm.setText(getString(R.string.confirm_no_price));
			// tv_price.setVisibility(View.GONE);
			for (OnPriceListener l : mOnPriceListener_list) {
				l.onPrice(null, false, false);
			}
			// tv_price.setVisibility(View.VISIBLE);
			// tv_price.setText("约");
			// tv_coupon_deductible.setText("0");
		}

	}

	/**
	 * 如果是城际，则显示城市未开通,isShow true则显示弹窗，false则不弹窗 并返回布尔型true为有开通，false则没开通
	 */
	public boolean getCityNotOpened(boolean isShow) {
		return true;
		// boolean isSame = false;
		// if (viewId != Value.VIEWID_SN) {
		// String location_city = mApplication.loctionCity;
		// if (location_city != null && !location_city.equals("")) {
		// List<Cities> list_city = db_line.readAllDB();
		// for (int i = 0; i < list_city.size(); i++) {
		// String in_city = list_city.get(i).getCity();
		// if (ToCity.getCityName(in_city).equals(
		// ToCity.getCityName(location_city))
		// && list_city.get(i).getIs_city()
		// .equals(Value.CITY_NOINCITY)) {
		// isSame = true;
		// break;
		// }
		//
		// }
		// } else {
		// isSame = false;
		// }
		//
		// final MyCityNotOpenedDailog notopenedDialog = new
		// MyCityNotOpenedDailog(
		// this);
		// if (notopenedDialog != null && !notopenedDialog.isShowing()
		// && !isSame && isShow) {
		// notopenedDialog.show();
		// }
		// new Handler().postDelayed(new Runnable() {
		//
		// @Override
		// public void run() {
		// if (notopenedDialog != null) {
		// notopenedDialog.dismiss();
		// }
		// }
		// }, 3000);
		// }
		// return isSame;
	}

	@Override
	public void onOrderFinish(int status, int flag,int own_expense,
			ArrayList<OfficialOrderList> list) {
		if (flag == Value.TYPE_ING) {
			getMyOrder_ING(true, list);
			MyOrderingDB db_myordering = new MyOrderingDB(this);
			db_myordering.onWriteDB_ing(context, list, true, null);
		} else if (flag == Value.TYPE_ALL) {
			db_myorder.onWriteDB(context, list, true, null);
		}

	}

	/**
	 * 线路加载完成
	 */
	@Override
	public void onLineFinish(boolean isSuccess) {
		if (isSuccess) {
			isLoadFinish = true;
			if (isLocation) {
				getCityNotOpened(true);
			}
		}
	}

	@Override
	public void onOrderDetailFinish(Officail_OrderInfo mOfficail_OrderInfo) {
		if (mOfficail_OrderInfo != null) {
			int status = Integer.parseInt(mOfficail_OrderInfo.getInfo()
					.getOrder_status());
			String order_id = mOfficail_OrderInfo.getInfo().getOrder_id();
			if (status < Value.ORDER_STATUS_OFFCAR
					|| status == Value.ORDER_STATUS_GAIPAI
					|| status == Value.ORDER_STATUS_KF_GAIPAI) {
				Intent intent = new Intent(this, StartServiceActivity.class);
				intent.putExtra(OrderMsg.extra_type, 1);
				intent.putExtra(OrderMsg.extra_order_id, order_id);
				startActivityForResult(intent, requestCode);
			} else if (status == Value.ORDER_STATUS_FINISH
					|| status == Value.ORDER_STATUS_OFFCAR) {
				Intent intent = new Intent(context,
						OrderEvaluationActivity2.class);
				intent.putExtra(OrderMsg.order_id_finish, order_id);
				intent.putExtra(OrderMsg.finish_type, OrderMsg.finish_ing);
				startActivityForResult(intent, requestCode);
			} else if (status == Value.ORDER_STATUS_CANCEL
					|| status == Value.ORDER_STATUS_KF_CANCEL) {
				Intent intent = new Intent(context, OrderCancelReason.class);
				intent.putExtra(OrderMsg.extra_order_id, order_id);
				startActivity(intent);
			} else if (status == Value.ORDER_STATUS_DELETE) {
				Intent intent = new Intent(context, OrderDelete.class);
				startActivity(intent);
			} else {
				Intent intent = new Intent(context,
						OrderEvaluationActivity2.class);
				intent.putExtra(OrderMsg.order_id_finish, order_id);
				intent.putExtra(OrderMsg.finish_type, OrderMsg.finish_all);
				startActivityForResult(intent, requestCode);
			}
		}
	}

	@Override
	public void onOrderCountFinish(int status, int orderstate) {
		if(status==MyOrderCountTask.STATUS_SUCCESS&&orderstate>0){
			tv_ordercount.setText(orderstate+"");
			tv_ordercount.setVisibility(View.VISIBLE);
			iv_new.setVisibility(View.VISIBLE);
		}else {
			tv_ordercount.setVisibility(View.GONE);
			iv_new.setVisibility(View.GONE);
		}
		// TODO Auto-generated method stub
		
	}
}
